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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Date: Tue, 20 Sep 2022 10:26:18 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.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=OXKOkKMY4UdF9Ksdqo8CuHT57dJsmzm4vvl1rc4TCl0=; b=SLjOaClct14qhVqFq0hljJwM9WgkPCiJUJuSHIT9pCFA6KOHuYZBvXVOWnKSuJbWKN6XKC56VZfkf6Bwb5K3bBGlI50JJbANpnDc9/FfeuZJQsZOKiz2wahrIDMVhcxgjlxALjwqJHjdpHUdEP3VR+V4NL3iyjhbp0SxfG4z/s7DHX3cNla72wRhoKjWa1I+J8FCuXt0peniiF+eXyg/oeo5BZmFclrz8gW1J7Irptx7b+po+mMKBjUf2hs5WN+ZcUmLpze4ZEnvo2bzYwrvmqXyHQovUiI7SJrnPHaEg4DXsAVYR3gYhNZGH7MYJJh2WNFZGHT1MrkjyOx28P5yGw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C3N1NryndL86A9mPwLy+KiwhpDT+hJpFIN4WbJUgPW/4KYEm8iaYbZkRMM6ioHsihftJjOb8yyGAQVH48j+3iNJK8f1aQEOhEypSBxPCVIkxK+xQJuGRJVVKID9WWkZm6V3g6hz6tUIJU6MVyG1WuvtNP98m/jRgP8y/TDwRpMCnS0WQSlWRBvMokTpJcRfLF7K/d0eregOguVhvqQz4otZQbCIu92KL8xGu5oVb0gvf+9oOaCZ1Khos5K5fRuKAaxJg0are992O1D6b2jT5zPwQUrpXCLQW/i2FixqxJDKwJiPWQrQxjbx1GUZycNsDeGjP/s59F/96BC0zTYpALg==
  • 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:27:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



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
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.


-boris





 


Rackspace

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