mbox series

[0/4] Yet another pci/vpci locking re-work

Message ID 20220216151628.1610777-1-andr2000@gmail.com (mailing list archive)
Headers show
Series Yet another pci/vpci locking re-work | expand

Message

Oleksandr Andrushchenko Feb. 16, 2022, 3:16 p.m. UTC
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Hello, all!

This is a yet another attempt to re-work the existing pci/vpci locking
scheme towards vPCI is going to be used for guests.
For more details on the previous attempts and their flaws please see [1], [2].

This work is based on the idea that it is possible to extend the
existing locking scheme by additionally providing a global read/write lock:

This way most of the code continues to use pcidevs_{lock|unlock}, so
only minor changes are required which do not lead to functional changes
seen by the users: these become readers with respect to the new rwlock
and they acquire _pcidevs_lock as before.

As to the writers (those which can add/remove pci devices and their
respective pdev) we need to make them use the new rwlock in write mode.
For that we introduce pcidevs_write_{un}lock helpers.

Those users, which do not add/remove pdevs and are only interested in
pdev->vpci or simple pdev's list traversal, will use
pcidevs_read_{lock|unlock} which only acquires the rwlock in read mode
without acquiring _pcidevs_lock. This is to make sure there is no
unnecessary contention for the later. For the cases when it is required
to make sure that no other CPU can access critical sections under the
read lock (modify_bars for example) it is possible to upgrade it to a
normal pcidevs_lock due to both read lock and _pcidevs_lock allow
recursion.

The series was tested on:
 - x86 PVH Dom0 and doesn't break it.
 - x86 HVM with PCI passthrough to DomU and doesn't break it.

Thank you,
Oleksandr

[1] https://lore.kernel.org/xen-devel/20180717094830.54806-2-roger.pau@citrix.com/
[2] https://lore.kernel.org/all/20220204063459.680961-4-andr2000@gmail.com/

Oleksandr Andrushchenko (4):
  pci: add rwlock to pcidevs_lock machinery
  vpci: restrict unhandled read/write operations for guests
  vpci: use pcidevs locking to protect MMIO handlers
  vpci: resolve possible clash while removing BAR overlaps

 xen/arch/x86/hvm/vmsi.c       | 24 +++++++++++--
 xen/drivers/passthrough/pci.c | 65 +++++++++++++++++++++++++++++------
 xen/drivers/vpci/header.c     | 30 ++++++++++++++--
 xen/drivers/vpci/msi.c        | 21 +++++++----
 xen/drivers/vpci/msix.c       | 55 +++++++++++++++++++++++++----
 xen/drivers/vpci/vpci.c       | 34 +++++++++++++++---
 xen/include/xen/pci.h         |  9 +++++
 xen/include/xen/vpci.h        |  2 +-
 8 files changed, 205 insertions(+), 35 deletions(-)