14 Sep, 2016

1 commit

  • We get a few warnings when building kernel with W=1:
    drivers/vfio/platform/vfio_platform_common.c:76:5: warning: no previous prototype for 'vfio_platform_acpi_call_reset' [-Wmissing-prototypes]
    drivers/vfio/platform/vfio_platform_common.c:98:6: warning: no previous prototype for 'vfio_platform_acpi_has_reset' [-Wmissing-prototypes]
    drivers/vfio/platform/vfio_platform_common.c:640:5: warning: no previous prototype for 'vfio_platform_of_probe' [-Wmissing-prototypes]
    drivers/vfio/platform/reset/vfio_platform_amdxgbe.c:59:5: warning: no previous prototype for 'vfio_platform_amdxgbe_reset' [-Wmissing-prototypes]
    drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c:60:5: warning: no previous prototype for 'vfio_platform_calxedaxgmac_reset' [-Wmissing-prototypes]
    ....

    In fact, these functions are only used in the file in which they are
    declared and don't need a declaration, but can be made static.
    so this patch marks these functions with 'static'.

    Signed-off-by: Baoyou Xie
    Acked-by: Arnd Bergmann
    Reviewed-by: Eric Auger
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Baoyou Xie
     

20 Jul, 2016

9 commits

  • Release call is ignoring the return code from reset call and can
    potentially continue even though reset call failed.

    If reset_required module parameter is set, this patch is going
    to validate the return code and will cause stack dump with
    WARN_ON and warn the user of failure.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Eric Auger
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • Open call is ignoring the return code from reset call and can
    potentially continue even though reset call failed.

    If reset_required module parameter is set, this patch is going
    to validate the return code and will abort open if reset fails.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • The code was allowing platform devices to be used without a supporting
    VFIO reset driver. The hardware can be left in some inconsistent state
    after a guest machine abort.

    The reset driver will put the hardware back to safe state and disable
    interrupts before returning the control back to the host machine.

    Adding a new reset_required kernel module option to platform VFIO drivers.
    The default value is true for the DT and ACPI based drivers.
    The reset requirement value for AMBA drivers is set to false and is
    unchangeable to maintain the existing functionality.

    New requirements are:
    1. A reset function needs to be implemented by the corresponding driver
    via DT/ACPI.
    2. The reset function needs to be discovered via DT/ACPI.

    The probe of the driver will fail if any of the above conditions are
    not satisfied.

    Signed-off-by: Sinan Kaya
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • The device tree code checks for the presence of a reset driver and calls
    the of_reset function pointer by looking up the reset driver as a module.

    ACPI defines _RST method to perform device level reset. After the _RST
    method is executed, the OS can resume using the device. _RST method is
    expected to stop DMA transfers and IRQs.

    This patch introduces two functions as vfio_platform_acpi_has_reset and
    vfio_platform_acpi_call_reset. The has reset method is used to declare
    reset capability via the ioctl flag VFIO_DEVICE_FLAGS_RESET. The call
    reset function is used to execute the _RST ACPI method.

    Signed-off-by: Sinan Kaya
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • Getting ready to bring out extra debug information to the caller
    so that more verbose information can be printed when an error is
    observed.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • The code is using the compatible DT string to associate a reset driver
    with the actual device itself. The compatible string does not exist on
    ACPI based systems. HID is the unique identifier for a device driver
    instead.

    Signed-off-by: Sinan Kaya
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • Creating a new function to determine if this driver supports reset
    function or not. This is an attempt to abstract device tree calls
    from the rest of the code.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Eric Auger
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • The reset call sequence seems to replicate itself multiple times
    across the file. Grouping them together for maintenance reasons.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Eric Auger
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Sinan Kaya
     
  • Renaming the reset function to of_reset as it is only used
    by the device tree based platforms.

    Signed-off-by: Sinan Kaya
    Reviewed-by: Eric Auger
    Reviewed-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Sinan Kaya
     

23 Jun, 2016

1 commit

  • The vfio No-IOMMU mode was supported by this
    'commit 03a76b60f8ba2797 ("vfio: Include No-IOMMU mode")',
    but it only support vfio-pci.

    Using vfio_iommu_group_get/put, but not iommu_group_get/put,
    the platform devices can be exposed to userspace with
    CONFIG_VFIO_NOIOMMU and the "enable_unsafe_noiommu_mode"
    option enabled.

    From 'commit 03a76b60f8ba2797 ("vfio: Include No-IOMMU mode")',
    "This should make it very clear that this mode is not safe.
    Additionally, CAP_SYS_RAWIO privileges are necessary to work
    with groups and containers using this mode. Groups making
    use of this support are named /dev/vfio/noiommu-$GROUP and
    can only make use of the special VFIO_NOIOMMU_IOMMU for the
    container. Use of this mode, specifically binding a device
    without a native IOMMU group to a VFIO bus driver will taint
    the kernel and should therefore not be considered supported."

    Signed-off-by: Peng Fan
    Cc: Eric Auger
    Cc: Baptiste Reynal
    Cc: Alex Williamson
    Reviewed-by: Eric Auger
    Signed-off-by: Alex Williamson

    Peng Fan
     

28 Feb, 2016

1 commit

  • Calling return copy_to_user(...) in an ioctl will not
    do the right thing if there's a pagefault:
    copy_to_user returns the number of bytes not copied
    in this case.

    Fix up vfio to do
    return copy_to_user(...)) ?
    -EFAULT : 0;

    everywhere.

    Cc: stable@vger.kernel.org
    Signed-off-by: Michael S. Tsirkin
    Signed-off-by: Alex Williamson

    Michael S. Tsirkin
     

22 Dec, 2015

1 commit

  • This loop ends with count set to -1 and not zero so the warning message
    isn't printed when it should be. I've fixed this by change the postop
    to a preop.

    Fixes: 0990822c9866 ('VFIO: platform: reset: AMD xgbe reset module')
    Signed-off-by: Dan Carpenter
    Reviewed-by: Eric Auger
    Signed-off-by: Alex Williamson

    Dan Carpenter
     

21 Nov, 2015

1 commit


20 Nov, 2015

1 commit


04 Nov, 2015

10 commits

  • This patch introduces a module that registers and implements a low-level
    reset function for the AMD XGBE device.

    it performs the following actions:
    - reset the PHY
    - disable auto-negotiation
    - disable & clear auto-negotiation IRQ
    - soft-reset the MAC

    Those tiny pieces of code are inherited from the native xgbe driver.

    Signed-off-by: Eric Auger
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • In the current code the vfio_platform_region is copied on the stack.
    As a consequence the ioaddr address is not iounmapped in the vfio
    platform driver (vfio_platform_regions_cleanup). The patch uses the
    pointer to the region instead.

    Signed-off-by: Eric Auger
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • It might be helpful for the end-user to check the device reset
    function was found by the vfio platform reset framework.

    Lets store a pointer to the struct device in vfio_platform_device
    and trace when the reset function is called or not found.

    Signed-off-by: Eric Auger
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • Remove the static lookup table and use the dynamic list of registered
    reset functions instead. Also load the reset module through its alias.
    The reset struct module pointer is stored in vfio_platform_device.

    We also remove the useless struct device pointer parameter in
    vfio_platform_get_reset.

    This patch fixes the issue related to the usage of __symbol_get, which
    besides from being moot, prevented compilation with CONFIG_MODULES
    disabled.

    Also usage of MODULE_ALIAS makes possible to add a new reset module
    without needing to update the framework. This was suggested by Arnd.

    Signed-off-by: Eric Auger
    Reported-by: Arnd Bergmann
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • Let's retrieve the compatibility string on probe and store it
    in the vfio_platform_device struct

    Signed-off-by: Eric Auger
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • This patch adds the reset function registration/unregistration.
    This is handled through the module_vfio_reset_handler macro. This
    latter also defines a MODULE_ALIAS which simplifies the load from
    vfio-platform.

    Signed-off-by: Eric Auger
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • The module_vfio_reset_handler macro
    - define a module alias
    - implement module init/exit function which respectively registers
    and unregisters the reset function.

    Signed-off-by: Eric Auger
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • In preparation for subsequent changes in reset function lookup,
    lets introduce a dynamic list of reset combos (compat string,
    reset module, reset function). The list can be populated/voided with
    vfio_platform_register/unregister_reset. Those are not yet used in
    this patch.

    Signed-off-by: Eric Auger
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • To prepare for vfio platform reset rework let's build
    vfio_platform_common.c and vfio_platform_irq.c in a separate
    module from vfio-platform and vfio-amba. This makes possible
    to have separate module inits and works around a race between
    platform driver init and vfio reset module init: that way we
    make sure symbols exported by base are available when vfio-platform
    driver gets probed.

    The open/release being implemented in the base module, the ref
    count is applied to the parent module instead.

    Signed-off-by: Eric Auger
    Suggested-by: Arnd Bergmann
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • vfio_platform_{read,write}_mmio() call ioremap_nocache() to map
    a region of io memory, which they store in struct vfio_platform_region to
    be eventually re-used, or unmapped by vfio_platform_regions_cleanup().

    These functions receive a copy of their struct vfio_platform_region
    argument on the stack - so these mapped areas are always allocated, and
    always leaked.

    Pass this argument as a pointer instead.

    Fixes: 6e3f26456009 "vfio/platform: read and write support for the device fd"
    Signed-off-by: James Morse
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    James Morse
     

28 Oct, 2015

1 commit

  • The vfio platform driver currently sets the IRQ_NOAUTOEN before
    doing the request_irq to properly handle the user masking. However
    it does not clear it when de-assigning the IRQ. This brings issues
    when loading the native driver again which may not explicitly enable
    the IRQ. This problem was observed with xgbe driver.

    Signed-off-by: Eric Auger
    Signed-off-by: Alex Williamson

    Eric Auger
     

22 Jun, 2015

4 commits

  • This patch enables building VFIO platform and derivatives on ARM64.

    Signed-off-by: Eric Auger
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • This patch introduces a module that registers and implements a basic
    reset function for the Calxeda xgmac device. This latter basically disables
    interrupts and stops DMA transfers.

    The reset function code is inherited from the native calxeda xgmac driver.

    Signed-off-by: Eric Auger
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • The reset function lookup happens on vfio-platform probe. The reset
    module load is requested and a reference to the function symbol is
    hold. The reference is released on vfio-platform remove.

    Signed-off-by: Eric Auger
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Eric Auger
     
  • A new reset callback is introduced. If this callback is populated,
    the reset is invoked on device first open/last close or upon userspace
    ioctl. The modality is exposed on VFIO_DEVICE_GET_INFO.

    Signed-off-by: Eric Auger
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Eric Auger
     

18 Jun, 2015

1 commit

  • This patch introduces the vfio_platform_reset_combo struct that
    stores all the information useful to handle the reset modality:
    compat string, name of the reset function, name of the module that
    implements the reset function. A lookup table of such structures
    is added, currently void.

    Signed-off-by: Eric Auger
    Acked-by: Baptiste Reynal
    Tested-by: Baptiste Reynal
    Signed-off-by: Alex Williamson

    Eric Auger
     

17 Mar, 2015

9 commits

  • An unintended consequence of commit 42ac9bd18d4f ("vfio: initialize
    the virqfd workqueue in VFIO generic code") is that the vfio module
    is renamed to vfio_core so that it can include both vfio and virqfd.
    That's a user visible change that may break module loading scritps
    and it imposes eventfd support as a dependency on the core vfio code,
    which it's really not. virqfd is intended to be provided as a service
    to vfio bus drivers, so instead of wrapping it into vfio.ko, we can
    make it a stand-alone module toggled by vfio bus drivers. This has
    the additional benefit of removing initialization and exit from the
    core vfio code.

    Signed-off-by: Alex Williamson

    Alex Williamson
     
  • With this patch the VFIO user will be able to set an eventfd that can be
    used in order to mask and unmask IRQs of platform devices.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • Level sensitive interrupts are exposed as maskable and automasked
    interrupts and are masked and disabled automatically when they fire.

    Signed-off-by: Antonios Motakis
    [Baptiste Reynal: Move masked interrupt initialization from "vfio/platform:
    trigger an interrupt via eventfd"]
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • This patch allows to set an eventfd for a platform device's interrupt,
    and also to trigger the interrupt eventfd from userspace for testing.
    Level sensitive interrupts are marked as maskable and are handled in
    a later patch. Edge triggered interrupts are not advertised as maskable
    and are implemented here using a simple and efficient IRQ handler.

    Signed-off-by: Antonios Motakis
    [Baptiste Reynal: fix masked interrupt initialization]
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • This patch is a skeleton for the VFIO_DEVICE_SET_IRQS IOCTL, around which
    most IRQ functionality is implemented in VFIO.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • Return information for the interrupts exposed by the device.
    This patch extends VFIO_DEVICE_GET_INFO with the number of IRQs
    and enables VFIO_DEVICE_GET_IRQ_INFO.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • Allow to memory map the MMIO regions of the device so userspace can
    directly access them. PIO regions are not being handled at this point.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • VFIO returns a file descriptor which we can use to manipulate the memory
    regions of the device. Usually, the user will mmap memory regions that are
    addressable on page boundaries, however for memory regions where this is
    not the case we cannot provide mmap functionality due to security concerns.
    For this reason we also allow to use read and write functions to the file
    descriptor pointing to the memory regions.

    We implement this functionality only for MMIO regions of platform devices;
    PIO regions are not being handled at this point.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis
     
  • This patch enables the IOCTLs VFIO_DEVICE_GET_REGION_INFO ioctl call,
    which allows the user to learn about the available MMIO resources of
    a device.

    Signed-off-by: Antonios Motakis
    Signed-off-by: Baptiste Reynal
    Reviewed-by: Eric Auger
    Tested-by: Eric Auger
    Signed-off-by: Alex Williamson

    Antonios Motakis