12 Oct, 2013

1 commit

  • In vfio_iommu_type1.c there is a bug in vfio_dma_do_map, when checking
    that pages are not already mapped. Since the check is being done in a
    for loop nested within the main loop, breaking out of it does not create
    the intended behavior. If the underlying IOMMU driver returns a non-NULL
    value, this will be ignored and mapping the DMA range will be attempted
    anyway, leading to unpredictable behavior.

    This interracts badly with the ARM SMMU driver issue fixed in the patch
    that was submitted with the title:
    "[PATCH 2/2] ARM: SMMU: return NULL on error in arm_smmu_iova_to_phys"
    Both fixes are required in order to use the vfio_iommu_type1 driver
    with an ARM SMMU.

    This patch refactors the function slightly, in order to also make this
    kind of bug less likely.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Alex Williamson

    Antonios Motakis
     

05 Sep, 2013

2 commits

  • The current VFIO_DEVICE_RESET interface only maps to PCI use cases
    where we can isolate the reset to the individual PCI function. This
    means the device must support FLR (PCIe or AF), PM reset on D3hot->D0
    transition, device specific reset, or be a singleton device on a bus
    for a secondary bus reset. FLR does not have widespread support,
    PM reset is not very reliable, and bus topology is dictated by the
    system and device design. We need to provide a means for a user to
    induce a bus reset in cases where the existing mechanisms are not
    available or not reliable.

    This device specific extension to VFIO provides the user with this
    ability. Two new ioctls are introduced:
    - VFIO_DEVICE_PCI_GET_HOT_RESET_INFO
    - VFIO_DEVICE_PCI_HOT_RESET

    The first provides the user with information about the extent of
    devices affected by a hot reset. This is essentially a list of
    devices and the IOMMU groups they belong to. The user may then
    initiate a hot reset by calling the second ioctl. We must be
    careful that the user has ownership of all the affected devices
    found via the first ioctl, so the second ioctl takes a list of file
    descriptors for the VFIO groups affected by the reset. Each group
    must have IOMMU protection established for the ioctl to succeed.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • Having PCIe/PCI-X capability isn't enough to assume that there are
    extended capabilities. Both specs define that the first capability
    header is all zero if there are no extended capabilities. Testing
    for this avoids an erroneous message about hiding capability 0x0 at
    offset 0x100.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

28 Aug, 2013

1 commit

  • eventfd_fget() tests to see whether the file is an eventfd file, which
    we then immediately pass to eventfd_ctx_fileget(), which again tests
    whether the file is an eventfd file. Simplify slightly by using
    fdget() so that we only test that we're looking at an eventfd once.
    fget() could also be used, but fdget() makes use of fget_light() for
    another slight optimization.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

23 Aug, 2013

2 commits

  • Add the default O_CLOEXEC flag for device file descriptors. This is
    generally considered a safer option as it allows the user a race free
    option to decide whether file descriptors are inherited across exec,
    with the default avoiding file descriptor leaks.

    Reported-by: Yann Droneaud
    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • Macro get_unused_fd() is used to allocate a file descriptor with
    default flags. Those default flags (0) can be "unsafe":
    O_CLOEXEC must be used by default to not leak file descriptor
    across exec().

    Instead of macro get_unused_fd(), functions anon_inode_getfd()
    or get_unused_fd_flags() should be used with flags given by userspace.
    If not possible, flags should be set to O_CLOEXEC to provide userspace
    with a default safe behavor.

    In a further patch, get_unused_fd() will be removed so that
    new code start using anon_inode_getfd() or get_unused_fd_flags()
    with correct flags.

    This patch replaces calls to get_unused_fd() with equivalent call to
    get_unused_fd_flags(0) to preserve current behavor for existing code.

    The hard coded flag value (0) should be reviewed on a per-subsystem basis,
    and, if possible, set to O_CLOEXEC.

    Signed-off-by: Yann Droneaud
    Link: http://lkml.kernel.org/r/cover.1376327678.git.ydroneaud@opteya.com
    Signed-off-by: Alex Williamson

    Yann Droneaud
     

06 Aug, 2013

1 commit

  • VFIO is designed to be used via ioctls on file descriptors
    returned by VFIO.

    However in some situations support for an external user is required.
    The first user is KVM on PPC64 (SPAPR TCE protocol) which is going to
    use the existing VFIO groups for exclusive access in real/virtual mode
    on a host to avoid passing map/unmap requests to the user space which
    would made things pretty slow.

    The protocol includes:

    1. do normal VFIO init operation:
    - opening a new container;
    - attaching group(s) to it;
    - setting an IOMMU driver for a container.
    When IOMMU is set for a container, all groups in it are
    considered ready to use by an external user.

    2. User space passes a group fd to an external user.
    The external user calls vfio_group_get_external_user()
    to verify that:
    - the group is initialized;
    - IOMMU is set for it.
    If both checks passed, vfio_group_get_external_user()
    increments the container user counter to prevent
    the VFIO group from disposal before KVM exits.

    3. The external user calls vfio_external_user_iommu_id()
    to know an IOMMU ID. PPC64 KVM uses it to link logical bus
    number (LIOBN) with IOMMU ID.

    4. When the external KVM finishes, it calls
    vfio_group_put_external_user() to release the VFIO group.
    This call decrements the container user counter.
    Everything gets released.

    The "vfio: Limit group opens" patch is also required for the consistency.

    Signed-off-by: Alexey Kardashevskiy
    Signed-off-by: Alex Williamson

    Alexey Kardashevskiy
     

25 Jul, 2013

3 commits

  • If an attempt is made to unbind a device from vfio-pci while that
    device is in use, the request is blocked until the device becomes
    unused. Unfortunately, that unbind path still grabs the device_lock,
    which certain things like __pci_reset_function() also want to take.
    This means we need to try to acquire the locks ourselves and use the
    pre-locked version, __pci_reset_function_locked().

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • Remove debugging WARN_ON if we get a spurious notify for a group that
    no longer exists. No reports of anyone hitting this, but it would
    likely be a race and not a bug if they did.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • BUS_NOTIFY_DEL_DEVICE triggers IOMMU drivers to remove devices from
    their iommu group, but there's really nothing we can do about it at
    this point. If the device is in use, then the vfio sub-driver will
    block the device_del from completing until it's released. If the
    device is not in use or not owned by a vfio sub-driver, then we
    really don't care that it's being removed.

    The current code can be triggered just by unloading an sr-iov driver
    (ex. igb) while the VFs are attached to vfio-pci because it makes an
    incorrect assumption about the ordering of driver remove callbacks
    vs the DEL_DEVICE notification.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

11 Jul, 2013

1 commit

  • Pull vfio updates from Alex Williamson:
    "Largely hugepage support for vfio/type1 iommu and surrounding cleanups
    and fixes"

    * tag 'vfio-v3.11' of git://github.com/awilliam/linux-vfio:
    vfio/type1: Fix leak on error path
    vfio: Limit group opens
    vfio/type1: Fix missed frees and zero sized removes
    vfio: fix documentation
    vfio: Provide module option to disable vfio_iommu_type1 hugepage support
    vfio: hugepage support for vfio_iommu_type1
    vfio: Convert type1 iommu to use rbtree

    Linus Torvalds
     

05 Jul, 2013

1 commit

  • Pull powerpc updates from Ben Herrenschmidt:
    "This is the powerpc changes for the 3.11 merge window. In addition to
    the usual bug fixes and small updates, the main highlights are:

    - Support for transparent huge pages by Aneesh Kumar for 64-bit
    server processors. This allows the use of 16M pages as transparent
    huge pages on kernels compiled with a 64K base page size.

    - Base VFIO support for KVM on power by Alexey Kardashevskiy

    - Wiring up of our nvram to the pstore infrastructure, including
    putting compressed oopses in there by Aruna Balakrishnaiah

    - Move, rework and improve our "EEH" (basically PCI error handling
    and recovery) infrastructure. It is no longer specific to pseries
    but is now usable by the new "powernv" platform as well (no
    hypervisor) by Gavin Shan.

    - I fixed some bugs in our math-emu instruction decoding and made it
    usable to emulate some optional FP instructions on processors with
    hard FP that lack them (such as fsqrt on Freescale embedded
    processors).

    - Support for Power8 "Event Based Branch" facility by Michael
    Ellerman. This facility allows what is basically "userspace
    interrupts" for performance monitor events.

    - A bunch of Transactional Memory vs. Signals bug fixes and HW
    breakpoint/watchpoint fixes by Michael Neuling.

    And more ... I appologize in advance if I've failed to highlight
    something that somebody deemed worth it."

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: (156 commits)
    pstore: Add hsize argument in write_buf call of pstore_ftrace_call
    powerpc/fsl: add MPIC timer wakeup support
    powerpc/mpic: create mpic subsystem object
    powerpc/mpic: add global timer support
    powerpc/mpic: add irq_set_wake support
    powerpc/85xx: enable coreint for all the 64bit boards
    powerpc/8xx: Erroneous double irq_eoi() on CPM IRQ in MPC8xx
    powerpc/fsl: Enable CONFIG_E1000E in mpc85xx_smp_defconfig
    powerpc/mpic: Add get_version API both for internal and external use
    powerpc: Handle both new style and old style reserve maps
    powerpc/hw_brk: Fix off by one error when validating DAWR region end
    powerpc/pseries: Support compression of oops text via pstore
    powerpc/pseries: Re-organise the oops compression code
    pstore: Pass header size in the pstore write callback
    powerpc/powernv: Fix iommu initialization again
    powerpc/pseries: Inform the hypervisor we are using EBB regs
    powerpc/perf: Add power8 EBB support
    powerpc/perf: Core EBB support for 64-bit book3s
    powerpc/perf: Drop MMCRA from thread_struct
    powerpc/perf: Don't enable if we have zero events
    ...

    Linus Torvalds
     

01 Jul, 2013

1 commit


29 Jun, 2013

1 commit


26 Jun, 2013

2 commits

  • vfio_group_fops_open attempts to limit concurrent sessions by
    disallowing opens once group->container is set. This really doesn't
    do what we want and allow for inconsistent behavior, for instance a
    group can be opened twice, then a container set giving the user two
    file descriptors to the group. But then it won't allow more to be
    opened. There's not much reason to have the group opened multiple
    times since most access is through devices or the container, so
    complete what the original code intended and only allow a single
    instance.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • With hugepage support we can only properly aligned and sized ranges.
    We only guarantee that we can unmap the same ranges mapped and not
    arbitrary sub-ranges. This means we might not free anything or might
    free more than requested. The vfio unmap interface started storing
    the unmapped size to return to userspace to handle this. This patch
    fixes a few places where we don't properly handle those cases, moves
    a memory allocation to a place where failure is an option and checks
    our loops to make sure we don't get into an infinite loop trying to
    remove an overlap.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

21 Jun, 2013

3 commits

  • Add a module option to vfio_iommu_type1 to disable IOMMU hugepage
    support. This causes iommu_map to only be called with single page
    mappings, disabling the IOMMU driver's ability to use hugepages.
    This option can be enabled by loading vfio_iommu_type1 with
    disable_hugepages=1 or dynamically through sysfs. If enabled
    dynamically, only new mappings are restricted.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • We currently send all mappings to the iommu in PAGE_SIZE chunks,
    which prevents the iommu from enabling support for larger page sizes.
    We still need to pin pages, which means we step through them in
    PAGE_SIZE chunks, but we can batch up contiguous physical memory
    chunks to allow the iommu the opportunity to use larger pages. The
    approach here is a bit different that the one currently used for
    legacy KVM device assignment. Rather than looking at the vma page
    size and using that as the maximum size to pass to the iommu, we
    instead simply look at whether the next page is physically
    contiguous. This means we might ask the iommu to map a 4MB region,
    while legacy KVM might limit itself to a maximum of 2MB.

    Splitting our mapping path also allows us to be smarter about locked
    memory because we can more easily unwind if the user attempts to
    exceed the limit. Therefore, rather than assuming that a mapping
    will result in locked memory, we test each page as it is pinned to
    determine whether it locks RAM vs an mmap'd MMIO region. This should
    result in better locking granularity and less locked page fudge
    factors in userspace.

    The unmap path uses the same algorithm as legacy KVM. We don't want
    to track the pfn for each mapping ourselves, but we need the pfn in
    order to unpin pages. We therefore ask the iommu for the iova to
    physical address translation, ask it to unpin a page, and see how many
    pages were actually unpinned. iommus supporting large pages will
    often return something bigger than a page here, which we know will be
    physically contiguous and we can unpin a batch of pfns. iommus not
    supporting large mappings won't see an improvement in batching here as
    they only unmap a page at a time.

    With this change, we also make a clarification to the API for mapping
    and unmapping DMA. We can only guarantee unmaps at the same
    granularity as used for the original mapping. In other words,
    unmapping a subregion of a previous mapping is not guaranteed and may
    result in a larger or smaller unmapping than requested. The size
    field in the unmapping structure is updated to reflect this.
    Previously this was unmodified on mapping, always returning the the
    requested unmap size. This is now updated to return the actual unmap
    size on success, allowing userspace to appropriately track mappings.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • We need to keep track of all the DMA mappings of an iommu container so
    that it can be automatically unmapped when the user releases the file
    descriptor. We currently do this using a simple list, where we merge
    entries with contiguous iovas and virtual addresses. Using a tree for
    this is a bit more efficient and allows us to use common code instead
    of inventing our own.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

20 Jun, 2013

2 commits

  • The enables VFIO on the pSeries platform, enabling user space
    programs to access PCI devices directly.

    Signed-off-by: Alexey Kardashevskiy
    Cc: David Gibson
    Signed-off-by: Paul Mackerras
    Acked-by: Alex Williamson
    Signed-off-by: Benjamin Herrenschmidt

    Alexey Kardashevskiy
     
  • VFIO implements platform independent stuff such as
    a PCI driver, BAR access (via read/write on a file descriptor
    or direct mapping when possible) and IRQ signaling.

    The platform dependent part includes IOMMU initialization
    and handling. This implements an IOMMU driver for VFIO
    which does mapping/unmapping pages for the guest IO and
    provides information about DMA window (required by a POWER
    guest).

    Cc: David Gibson
    Signed-off-by: Alexey Kardashevskiy
    Signed-off-by: Paul Mackerras
    Acked-by: Alex Williamson
    Signed-off-by: Benjamin Herrenschmidt

    Alexey Kardashevskiy
     

05 Jun, 2013

1 commit


03 May, 2013

1 commit

  • Pull vfio updates from Alex Williamson:
    "Changes include extension to support PCI AER notification to
    userspace, byte granularity of PCI config space and access to
    unarchitected PCI config space, better protection around IOMMU driver
    accesses, default file mode fix, and a few misc cleanups."

    * tag 'vfio-for-v3.10' of git://github.com/awilliam/linux-vfio:
    vfio: Set container device mode
    vfio: Use down_reads to protect iommu disconnects
    vfio: Convert container->group_lock to rwsem
    PCI/VFIO: use pcie_flags_reg instead of access PCI-E Capabilities Register
    vfio-pci: Enable raw access to unassigned config space
    vfio-pci: Use byte granularity in config map
    vfio: make local function vfio_pci_intx_unmask_handler() static
    VFIO-AER: Vfio-pci driver changes for supporting AER
    VFIO: Wrapper for getting reference to vfio_device

    Linus Torvalds
     

01 May, 2013

1 commit

  • Minor 0 is the VFIO container device (/dev/vfio/vfio). On it's own
    the container does not provide a user with any privileged access. It
    only supports API version check and extension check ioctls. Only by
    attaching a VFIO group to the container does it gain any access. Set
    the mode of the container to allow access.

    Signed-off-by: Alex Williamson

    Alex Williamson
     

30 Apr, 2013

1 commit

  • Pull PCI updates from Bjorn Helgaas:
    "PCI changes for the v3.10 merge window:

    PCI device hotplug
    - Remove ACPI PCI subdrivers (Jiang Liu, Myron Stowe)
    - Make acpiphp builtin only, not modular (Jiang Liu)
    - Add acpiphp mutual exclusion (Jiang Liu)

    Power management
    - Skip "PME enabled/disabled" messages when not supported (Rafael
    Wysocki)
    - Fix fallback to PCI_D0 (Rafael Wysocki)

    Miscellaneous
    - Factor quirk_io_region (Yinghai Lu)
    - Cache MSI capability offsets & cleanup (Gavin Shan, Bjorn Helgaas)
    - Clean up EISA resource initialization and logging (Bjorn Helgaas)
    - Fix prototype warnings (Andy Shevchenko, Bjorn Helgaas)
    - MIPS: Initialize of_node before scanning bus (Gabor Juhos)
    - Fix pcibios_get_phb_of_node() declaration "weak" annotation (Gabor
    Juhos)
    - Add MSI INTX_DISABLE quirks for AR8161/AR8162/etc (Xiong Huang)
    - Fix aer_inject return values (Prarit Bhargava)
    - Remove PME/ACPI dependency (Andrew Murray)
    - Use shared PCI_BUS_NUM() and PCI_DEVID() (Shuah Khan)"

    * tag 'pci-v3.10-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (63 commits)
    vfio-pci: Use cached MSI/MSI-X capabilities
    vfio-pci: Use PCI_MSIX_TABLE_BIR, not PCI_MSIX_FLAGS_BIRMASK
    PCI: Remove "extern" from function declarations
    PCI: Use PCI_MSIX_TABLE_BIR, not PCI_MSIX_FLAGS_BIRMASK
    PCI: Drop msi_mask_reg() and remove drivers/pci/msi.h
    PCI: Use msix_table_size() directly, drop multi_msix_capable()
    PCI: Drop msix_table_offset_reg() and msix_pba_offset_reg() macros
    PCI: Drop is_64bit_address() and is_mask_bit_support() macros
    PCI: Drop msi_data_reg() macro
    PCI: Drop msi_lower_address_reg() and msi_upper_address_reg() macros
    PCI: Drop msi_control_reg() macro and use PCI_MSI_FLAGS directly
    PCI: Use cached MSI/MSI-X offsets from dev, not from msi_desc
    PCI: Clean up MSI/MSI-X capability #defines
    PCI: Use cached MSI-X cap while enabling MSI-X
    PCI: Use cached MSI cap while enabling MSI interrupts
    PCI: Remove MSI/MSI-X cap check in pci_msi_check_device()
    PCI: Cache MSI/MSI-X capability offsets in struct pci_dev
    PCI: Use u8, not int, for PM capability offset
    [SCSI] megaraid_sas: Use correct #define for MSI-X capability
    PCI: Remove "extern" from function declarations
    ...

    Linus Torvalds
     

29 Apr, 2013

1 commit


26 Apr, 2013

1 commit


25 Apr, 2013

2 commits


15 Apr, 2013

1 commit


01 Apr, 2013

2 commits

  • Devices like be2net hide registers between the gaps in capabilities
    and architected regions of PCI config space. Our choices to support
    such devices is to either build an ever growing and unmanageable white
    list or rely on hardware isolation to protect us. These registers are
    really no different than MMIO or I/O port space registers, which we
    don't attempt to regulate, so treat PCI config space in the same way.

    Reported-by: Gavin Shan
    Signed-off-by: Alex Williamson
    Tested-by: Gavin Shan

    Alex Williamson
     
  • The config map previously used a byte per dword to map regions of
    config space to capabilities. Modulo a bug where we round the length
    of capabilities down instead of up, this theoretically works well and
    saves space so long as devices don't try to hide registers in the gaps
    between capabilities. Unfortunately they do exactly that so we need
    byte granularity on our config space map. Increase the allocation of
    the config map and split accesses at capability region boundaries.

    Signed-off-by: Alex Williamson
    Tested-by: Gavin Shan

    Alex Williamson
     

27 Mar, 2013

1 commit

  • The VFIO_DEVICE_SET_IRQS ioctl takes a start and count parameter, both
    of which are unsigned. We attempt to bounds check these, but fail to
    account for the case where start is a very large number, allowing
    start + count to wrap back into the valid range. Bounds check both
    start and start + count.

    Reported-by: Dan Carpenter
    Signed-off-by: Alex Williamson

    Alex Williamson
     

26 Mar, 2013

1 commit


16 Mar, 2013

1 commit


11 Mar, 2013

2 commits

  • - New VFIO_SET_IRQ ioctl option to pass the eventfd that is signaled when
    an error occurs in the vfio_pci_device

    - Register pci_error_handler for the vfio_pci driver

    - When the device encounters an error, the error handler registered by
    the vfio_pci driver gets invoked by the AER infrastructure

    - In the error handler, signal the eventfd registered for the device.

    - This results in the qemu eventfd handler getting invoked and
    appropriate action taken for the guest.

    Signed-off-by: Vijay Mohan Pandarathil
    Signed-off-by: Alex Williamson

    Vijay Mohan Pandarathil
     
  • - Added vfio_device_get_from_dev() as wrapper to get
    reference to vfio_device from struct device.

    - Added vfio_device_data() as a wrapper to get device_data from
    vfio_device.

    Signed-off-by: Vijay Mohan Pandarathil
    Signed-off-by: Alex Williamson

    Vijay Mohan Pandarathil
     

28 Feb, 2013

1 commit


25 Feb, 2013

1 commit


19 Feb, 2013

1 commit

  • PCI defines display class VGA regions at I/O port address 0x3b0, 0x3c0
    and MMIO address 0xa0000. As these are non-overlapping, we can ignore
    the I/O port vs MMIO difference and expose them both in a single
    region. We make use of the VGA arbiter around each access to
    configure chipset access as necessary.

    Signed-off-by: Alex Williamson

    Alex Williamson