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

Re: [PATCH v2] x86/vpt: Do not take pt_migrate rwlock in some cases


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Mon, 29 Mar 2021 12:40:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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-SenderADCheck; bh=4uq1zSz2PA08osRpyXxWzQ3BZyN1WJhZGJ1zPNuzRHE=; b=EaQ5FjUAKufS21jaRPvAAgKOZXZ6tWb9bgkwRty2OwdJrID2v7wLWovNMG+CuvgY2IrD4yhInmJNgWrWsFBvIdAEi6uXD4fYqjjLhk1ihcdiiqe3Nv7iC8egjNVbjtcfpobiiD2VHkVpdPBrN1g6vJXQPWnb4D+KheIGfAUjq1RMuQoDx9VcAZfOKd3peFvfDe5x2LVyZVElj6P5CcxYHcjx29UbIrjBgo4WSB1QCtDTtlxj91I7f7BqMUSGf33b2Ylo3z2cyDJMDRpIVFUyVcsOTJCZyeU9tK+oC+SU1+IXPvgQy9d52D0KiVBqwsR+ic90HsgnJuLdFbKzNJnbzg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FFHvRo3uANxE642aE8GEE7n0RL9gyzT05Jk332AowN8PUOiyD6dWym/wrZiqeQjxQxTIqGtMsZVXusaMNHwI7HFLN0EvwEb2nraJTHO3OUKkQh5gZcyf2v89M22wNpXh2g14RFW3S90WxpJcl2x8Ta8k/ZpxJ3A0h/GeNHj0gSIYNhLbVtMOqWS4WQASK3zAsj+Lfd0HRDQchbuT6tP6E+ytJquwV5ih1DRut9woAXSsK/UvlCoeWOnV9wZRwG+hxeXvcElVOcytlVYIxyQIS7DPVtdB3P/7IH5QrFL2axxblvsVyXaFhnfNLFZSKw/kvtU4DJlOcto2hDTDbjs1VQ==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <wl@xxxxxxx>, <stephen.s.brennan@xxxxxxxxxx>, <iwj@xxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 29 Mar 2021 10:40:52 +0000
  • Ironport-hdrordr: A9a23:4KhEEK6O2g/hosweogPXwXiEI+orLtY04lQ7vn1ZYSd+NuSFis Gjm+ka3xfoiDAXHEotg8yEJbPoexzh3LZPy800Ma25VAfr/FGpIoZr8Jf4z1TbdxHW3tV2kZ 1te60WMrDNJHBnkMf35xS5Gd48wN+BtJuln/va0m0Fd2BXQotLhj0JbTqzOEtwWQVAGN4VFI CE4NBGujqnfh0sH76GL1MCWPXOoMCOqYnvZgQICwVixA6Fiz6p77CSKWnk4j41VTRTzbA+tV XUigCR3NTZj9iX6D/5k1XS4ZNfhcf7xrJ4avCkp8AJJlzX+2SVTat7XbnqhkFRnMiO7xIQnM DIs1McOa1Img/sV0WUhTeo5AX6yjYp7BbZuC+lqF/uu9bwSj5/K+cpv/MhTjLj50AtvM5x3c twtgrz3fonbmKzoA3H69fFTB1snEavyEBS6dI7tHBDTZAYLIZYsI13xjIlLL47ACn45Io7ed Meav302fA+SyL/U1np+kNrwNCqQ00pGAaHTkUoqqWuokZrtUE84E0CyMMFmHAcsLo7Vplf/u zBdp9ljbdUU6YtHO5ALdZEZfHyJn3GQBrKPm7XCVP7FJsfM3aIj5Ls+r066MyjZZRg9up8pL 3xFHdj8UIicUPnDsODmLdR9ArWfWm7VTPxjulD+plQoNTHNfrWGBzGbGprv9qrov0ZDMGece 20IohqD/jqKnarMZpV3jf5R4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R1D ohSzavheA89vzlZjixHIQRpyajf89cpLtBI9q3/TCIoaYAgxeZbSQMN5ZVMpL4bKnZAX49bedE w4naB0etm9tpFguqb7TWIsFYyv34iquDj9lc5Boa2UgQ2pvFJVBrbrHXx5W4cRvQ1AP9SADMJX RsOKhaK1MBANF+wmUeUma9LMZHL69MTfgJD9hjnr7kFqWMke22vevPefIcZ60ewBPLasLm1Dtw ceY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Mar 29, 2021 at 11:56:56AM +0200, Jan Beulich wrote:
> On 27.03.2021 02:51, Boris Ostrovsky wrote:
> > Commit 8e76aef72820 ("x86/vpt: fix race when migrating timers between
> > vCPUs") addressed XSA-336 by introducing a per-domain rwlock that was
> > intended to protect periodic timer during VCPU migration. Since such
> > migration is an infrequent event no performance impact was expected.
> > 
> > Unfortunately this turned out not to be the case: on a fairly large
> > guest (92 VCPUs) we've observed as much as 40% TPCC performance
> > regression with some guest kernels. Further investigation pointed to
> > pt_migrate read lock taken in pt_update_irq() as the largest contributor
> > to this regression. With large number of VCPUs and large number of VMEXITs
> > (from where pt_update_irq() is always called) the update of an atomic in
> > read_lock() is thought to be the main cause.
> > 
> > Stephen Brennan analyzed locking pattern and classified lock users as
> > follows:
> > 
> > 1. Functions which read (maybe write) all periodic_time instances
> > attached to a particular vCPU. These are functions which use pt_vcpu_lock()
> > after the commit, such as pt_restore_timer(), pt_save_timer(), etc.
> > 2. Functions which want to modify a particular periodic_time object.
> > These guys lock whichever vCPU the periodic_time is attached to, but
> > since the vCPU could be modified without holding any lock, they are
> > vulnerable to the bug. Functions in this group use pt_lock(), such as
> > pt_timer_fn() or destroy_periodic_time().
> > 3. Functions which not only want to modify the periodic_time, but also
> > would like to modify the =vcpu= fields. These are create_periodic_time()
> > or pt_adjust_vcpu(). They create the locking imbalance bug for group 2,
> > but we can't simply hold 2 vcpu locks due to the deadlock risk.
> > 
> > Roger Monné then pointed out that group 1 functions don't really need
> > to hold the pt_migrate rwlock and that group 3 should be hardened by
> > holding appropriate vcpu's tm_lock when adding or deleting a timer
> > from its list.
> 
> I'm struggling some with the latter aspect: Is this to mean there is
> something wrong right now?

There's nothing wrong right now AFAICT , because per-vcpu users (ie:
type 1) also hold the rw lock in read mode when iterating over the
per-vcpu list.

> Or does "harden" really mean "just to be
> on the safe side" here?

If the per-domain rw lock is no longer read-locked by type 1 users
then type 2 and type 3 users need to make sure the per-vcpu lock is
taken before adding or removing items from the per-vcpu lists, or else
a type 1 user could see list corruption as a result of modifications
done by type 2 or 3 without holding the per-vcpu lock.

This again makes the locking logic more complicated than it was, so I
will try to get back with my vpt improvements so we can get rid of all
this at least on unstable. Hopefully the comments are clear enough to
follow the logic.

Roger.



 


Rackspace

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