1. 02 9月, 2021 1 次提交
  2. 19 7月, 2021 7 次提交
  3. 03 6月, 2021 2 次提交
  4. 26 4月, 2021 1 次提交
  5. 12 1月, 2021 2 次提交
  6. 04 11月, 2020 1 次提交
    • F
      vfio/pci: Bypass IGD init in case of -ENODEV · e4eccb85
      Fred Gao 提交于
      Bypass the IGD initialization when -ENODEV returns,
      that should be the case if opregion is not available for IGD
      or within discrete graphics device's option ROM,
      or host/lpc bridge is not found.
      
      Then use of -ENODEV here means no special device resources found
      which needs special care for VFIO, but we still allow other normal
      device resource access.
      
      Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
      Cc: Xiong Zhang <xiong.y.zhang@intel.com>
      Cc: Hang Yuan <hang.yuan@linux.intel.com>
      Cc: Stuart Summers <stuart.summers@intel.com>
      Signed-off-by: NFred Gao <fred.gao@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      e4eccb85
  7. 17 10月, 2020 1 次提交
  8. 13 10月, 2020 1 次提交
  9. 22 9月, 2020 1 次提交
  10. 24 8月, 2020 1 次提交
  11. 28 7月, 2020 4 次提交
  12. 17 7月, 2020 1 次提交
    • Z
      vfio/pci: fix racy on error and request eventfd ctx · b872d064
      Zeng Tao 提交于
      The vfio_pci_release call will free and clear the error and request
      eventfd ctx while these ctx could be in use at the same time in the
      function like vfio_pci_request, and it's expected to protect them under
      the vdev->igate mutex, which is missing in vfio_pci_release.
      
      This issue is introduced since commit 1518ac27 ("vfio/pci: fix memory
      leaks of eventfd ctx"),and since commit 5c5866c5 ("vfio/pci: Clear
      error and request eventfd ctx after releasing"), it's very easily to
      trigger the kernel panic like this:
      
      [ 9513.904346] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
      [ 9513.913091] Mem abort info:
      [ 9513.915871]   ESR = 0x96000006
      [ 9513.918912]   EC = 0x25: DABT (current EL), IL = 32 bits
      [ 9513.924198]   SET = 0, FnV = 0
      [ 9513.927238]   EA = 0, S1PTW = 0
      [ 9513.930364] Data abort info:
      [ 9513.933231]   ISV = 0, ISS = 0x00000006
      [ 9513.937048]   CM = 0, WnR = 0
      [ 9513.940003] user pgtable: 4k pages, 48-bit VAs, pgdp=0000007ec7d12000
      [ 9513.946414] [0000000000000008] pgd=0000007ec7d13003, p4d=0000007ec7d13003, pud=0000007ec728c003, pmd=0000000000000000
      [ 9513.956975] Internal error: Oops: 96000006 [#1] PREEMPT SMP
      [ 9513.962521] Modules linked in: vfio_pci vfio_virqfd vfio_iommu_type1 vfio hclge hns3 hnae3 [last unloaded: vfio_pci]
      [ 9513.972998] CPU: 4 PID: 1327 Comm: bash Tainted: G        W         5.8.0-rc4+ #3
      [ 9513.980443] Hardware name: Huawei TaiShan 2280 V2/BC82AMDC, BIOS 2280-V2 CS V3.B270.01 05/08/2020
      [ 9513.989274] pstate: 80400089 (Nzcv daIf +PAN -UAO BTYPE=--)
      [ 9513.994827] pc : _raw_spin_lock_irqsave+0x48/0x88
      [ 9513.999515] lr : eventfd_signal+0x6c/0x1b0
      [ 9514.003591] sp : ffff800038a0b960
      [ 9514.006889] x29: ffff800038a0b960 x28: ffff007ef7f4da10
      [ 9514.012175] x27: ffff207eefbbfc80 x26: ffffbb7903457000
      [ 9514.017462] x25: ffffbb7912191000 x24: ffff007ef7f4d400
      [ 9514.022747] x23: ffff20be6e0e4c00 x22: 0000000000000008
      [ 9514.028033] x21: 0000000000000000 x20: 0000000000000000
      [ 9514.033321] x19: 0000000000000008 x18: 0000000000000000
      [ 9514.038606] x17: 0000000000000000 x16: ffffbb7910029328
      [ 9514.043893] x15: 0000000000000000 x14: 0000000000000001
      [ 9514.049179] x13: 0000000000000000 x12: 0000000000000002
      [ 9514.054466] x11: 0000000000000000 x10: 0000000000000a00
      [ 9514.059752] x9 : ffff800038a0b840 x8 : ffff007ef7f4de60
      [ 9514.065038] x7 : ffff007fffc96690 x6 : fffffe01faffb748
      [ 9514.070324] x5 : 0000000000000000 x4 : 0000000000000000
      [ 9514.075609] x3 : 0000000000000000 x2 : 0000000000000001
      [ 9514.080895] x1 : ffff007ef7f4d400 x0 : 0000000000000000
      [ 9514.086181] Call trace:
      [ 9514.088618]  _raw_spin_lock_irqsave+0x48/0x88
      [ 9514.092954]  eventfd_signal+0x6c/0x1b0
      [ 9514.096691]  vfio_pci_request+0x84/0xd0 [vfio_pci]
      [ 9514.101464]  vfio_del_group_dev+0x150/0x290 [vfio]
      [ 9514.106234]  vfio_pci_remove+0x30/0x128 [vfio_pci]
      [ 9514.111007]  pci_device_remove+0x48/0x108
      [ 9514.115001]  device_release_driver_internal+0x100/0x1b8
      [ 9514.120200]  device_release_driver+0x28/0x38
      [ 9514.124452]  pci_stop_bus_device+0x68/0xa8
      [ 9514.128528]  pci_stop_and_remove_bus_device+0x20/0x38
      [ 9514.133557]  pci_iov_remove_virtfn+0xb4/0x128
      [ 9514.137893]  sriov_disable+0x3c/0x108
      [ 9514.141538]  pci_disable_sriov+0x28/0x38
      [ 9514.145445]  hns3_pci_sriov_configure+0x48/0xb8 [hns3]
      [ 9514.150558]  sriov_numvfs_store+0x110/0x198
      [ 9514.154724]  dev_attr_store+0x44/0x60
      [ 9514.158373]  sysfs_kf_write+0x5c/0x78
      [ 9514.162018]  kernfs_fop_write+0x104/0x210
      [ 9514.166010]  __vfs_write+0x48/0x90
      [ 9514.169395]  vfs_write+0xbc/0x1c0
      [ 9514.172694]  ksys_write+0x74/0x100
      [ 9514.176079]  __arm64_sys_write+0x24/0x30
      [ 9514.179987]  el0_svc_common.constprop.4+0x110/0x200
      [ 9514.184842]  do_el0_svc+0x34/0x98
      [ 9514.188144]  el0_svc+0x14/0x40
      [ 9514.191185]  el0_sync_handler+0xb0/0x2d0
      [ 9514.195088]  el0_sync+0x140/0x180
      [ 9514.198389] Code: b9001020 d2800000 52800022 f9800271 (885ffe61)
      [ 9514.204455] ---[ end trace 648de00c8406465f ]---
      [ 9514.212308] note: bash[1327] exited with preempt_count 1
      
      Cc: Qian Cai <cai@lca.pw>
      Cc: Alex Williamson <alex.williamson@redhat.com>
      Fixes: 1518ac27 ("vfio/pci: fix memory leaks of eventfd ctx")
      Signed-off-by: NZeng Tao <prime.zeng@hisilicon.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      b872d064
  13. 18 6月, 2020 1 次提交
  14. 10 6月, 2020 2 次提交
  15. 27 5月, 2020 1 次提交
    • Q
      vfio/pci: fix memory leaks of eventfd ctx · 1518ac27
      Qian Cai 提交于
      Finished a qemu-kvm (-device vfio-pci,host=0001:01:00.0) triggers a few
      memory leaks after a while because vfio_pci_set_ctx_trigger_single()
      calls eventfd_ctx_fdget() without the matching eventfd_ctx_put() later.
      Fix it by calling eventfd_ctx_put() for those memory in
      vfio_pci_release() before vfio_device_release().
      
      unreferenced object 0xebff008981cc2b00 (size 128):
        comm "qemu-kvm", pid 4043, jiffies 4294994816 (age 9796.310s)
        hex dump (first 32 bytes):
          01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de  ....kkkk.....N..
          ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff  ....kkkk........
        backtrace:
          [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c
          [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4
          [<000000005fcec025>] do_eventfd+0x54/0x1ac
          [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44
          [<00000000b819758c>] do_el0_svc+0x128/0x1dc
          [<00000000b244e810>] el0_sync_handler+0xd0/0x268
          [<00000000d495ef94>] el0_sync+0x164/0x180
      unreferenced object 0x29ff008981cc4180 (size 128):
        comm "qemu-kvm", pid 4043, jiffies 4294994818 (age 9796.290s)
        hex dump (first 32 bytes):
          01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de  ....kkkk.....N..
          ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff  ....kkkk........
        backtrace:
          [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c
          [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4
          [<000000005fcec025>] do_eventfd+0x54/0x1ac
          [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44
          [<00000000b819758c>] do_el0_svc+0x128/0x1dc
          [<00000000b244e810>] el0_sync_handler+0xd0/0x268
          [<00000000d495ef94>] el0_sync+0x164/0x180
      Signed-off-by: NQian Cai <cai@lca.pw>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      1518ac27
  16. 18 5月, 2020 2 次提交
    • A
      vfio-pci: Invalidate mmaps and block MMIO access on disabled memory · abafbc55
      Alex Williamson 提交于
      Accessing the disabled memory space of a PCI device would typically
      result in a master abort response on conventional PCI, or an
      unsupported request on PCI express.  The user would generally see
      these as a -1 response for the read return data and the write would be
      silently discarded, possibly with an uncorrected, non-fatal AER error
      triggered on the host.  Some systems however take it upon themselves
      to bring down the entire system when they see something that might
      indicate a loss of data, such as this discarded write to a disabled
      memory space.
      
      To avoid this, we want to try to block the user from accessing memory
      spaces while they're disabled.  We start with a semaphore around the
      memory enable bit, where writers modify the memory enable state and
      must be serialized, while readers make use of the memory region and
      can access in parallel.  Writers include both direct manipulation via
      the command register, as well as any reset path where the internal
      mechanics of the reset may both explicitly and implicitly disable
      memory access, and manipulation of the MSI-X configuration, where the
      MSI-X vector table resides in MMIO space of the device.  Readers
      include the read and write file ops to access the vfio device fd
      offsets as well as memory mapped access.  In the latter case, we make
      use of our new vma list support to zap, or invalidate, those memory
      mappings in order to force them to be faulted back in on access.
      
      Our semaphore usage will stall user access to MMIO spaces across
      internal operations like reset, but the user might experience new
      behavior when trying to access the MMIO space while disabled via the
      PCI command register.  Access via read or write while disabled will
      return -EIO and access via memory maps will result in a SIGBUS.  This
      is expected to be compatible with known use cases and potentially
      provides better error handling capabilities than present in the
      hardware, while avoiding the more readily accessible and severe
      platform error responses that might otherwise occur.
      
      Fixes: CVE-2020-12888
      Reviewed-by: NPeter Xu <peterx@redhat.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      abafbc55
    • A
      vfio-pci: Fault mmaps to enable vma tracking · 11c4cd07
      Alex Williamson 提交于
      Rather than calling remap_pfn_range() when a region is mmap'd, setup
      a vm_ops handler to support dynamic faulting of the range on access.
      This allows us to manage a list of vmas actively mapping the area that
      we can later use to invalidate those mappings.  The open callback
      invalidates the vma range so that all tracking is inserted in the
      fault handler and removed in the close handler.
      Reviewed-by: NPeter Xu <peterx@redhat.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      11c4cd07
  17. 24 3月, 2020 6 次提交
    • A
      vfio/pci: Cleanup .probe() exit paths · b66574a3
      Alex Williamson 提交于
      The cleanup is getting a tad long.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      b66574a3
    • A
      vfio/pci: Remove dev_fmt definition · 959e1b75
      Alex Williamson 提交于
      It currently results in messages like:
      
       "vfio-pci 0000:03:00.0: vfio_pci: ..."
      
      Which is quite a bit redundant.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      959e1b75
    • A
      vfio/pci: Add sriov_configure support · 137e5531
      Alex Williamson 提交于
      With the VF Token interface we can now expect that a vfio userspace
      driver must be in collaboration with the PF driver, an unwitting
      userspace driver will not be able to get past the GET_DEVICE_FD step
      in accessing the device.  We can now move on to actually allowing
      SR-IOV to be enabled by vfio-pci on the PF.  Support for this is not
      enabled by default in this commit, but it does provide a module option
      for this to be enabled (enable_sriov=1).  Enabling VFs is rather
      straightforward, except we don't want to risk that a VF might get
      autoprobed and bound to other drivers, so a bus notifier is used to
      "capture" VFs to vfio-pci using the driver_override support.  We
      assume any later action to bind the device to other drivers is
      condoned by the system admin and allow it with a log warning.
      
      vfio-pci will disable SR-IOV on a PF before releasing the device,
      allowing a VF driver to be assured other drivers cannot take over the
      PF and that any other userspace driver must know the shared VF token.
      This support also does not provide a mechanism for the PF userspace
      driver itself to manipulate SR-IOV through the vfio API.  With this
      patch SR-IOV can only be enabled via the host sysfs interface and the
      PF driver user cannot create or remove VFs.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      137e5531
    • A
      vfio: Introduce VFIO_DEVICE_FEATURE ioctl and first user · 43eeeecc
      Alex Williamson 提交于
      The VFIO_DEVICE_FEATURE ioctl is meant to be a general purpose, device
      agnostic ioctl for setting, retrieving, and probing device features.
      This implementation provides a 16-bit field for specifying a feature
      index, where the data porition of the ioctl is determined by the
      semantics for the given feature.  Additional flag bits indicate the
      direction and nature of the operation; SET indicates user data is
      provided into the device feature, GET indicates the device feature is
      written out into user data.  The PROBE flag augments determining
      whether the given feature is supported, and if provided, whether the
      given operation on the feature is supported.
      
      The first user of this ioctl is for setting the vfio-pci VF token,
      where the user provides a shared secret key (UUID) on a SR-IOV PF
      device, which users must provide when opening associated VF devices.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      43eeeecc
    • A
      vfio/pci: Introduce VF token · cc20d799
      Alex Williamson 提交于
      If we enable SR-IOV on a vfio-pci owned PF, the resulting VFs are not
      fully isolated from the PF.  The PF can always cause a denial of service
      to the VF, even if by simply resetting itself.  The degree to which a PF
      can access the data passed through a VF or interfere with its operation
      is dependent on a given SR-IOV implementation.  Therefore we want to
      avoid a scenario where an existing vfio-pci based userspace driver might
      assume the PF driver is trusted, for example assigning a PF to one VM
      and VF to another with some expectation of isolation.  IOMMU grouping
      could be a solution to this, but imposes an unnecessarily strong
      relationship between PF and VF drivers if they need to operate with the
      same IOMMU context.  Instead we introduce a "VF token", which is
      essentially just a shared secret between PF and VF drivers, implemented
      as a UUID.
      
      The VF token can be set by a vfio-pci based PF driver and must be known
      by the vfio-pci based VF driver in order to gain access to the device.
      This allows the degree to which this VF token is considered secret to be
      determined by the applications and environment.  For example a VM might
      generate a random UUID known only internally to the hypervisor while a
      userspace networking appliance might use a shared, or even well know,
      UUID among the application drivers.
      
      To incorporate this VF token, the VFIO_GROUP_GET_DEVICE_FD interface is
      extended to accept key=value pairs in addition to the device name.  This
      allows us to most easily deny user access to the device without risk
      that existing userspace drivers assume region offsets, IRQs, and other
      device features, leading to more elaborate error paths.  The format of
      these options are expected to take the form:
      
      "$DEVICE_NAME $OPTION1=$VALUE1 $OPTION2=$VALUE2"
      
      Where the device name is always provided first for compatibility and
      additional options are specified in a space separated list.  The
      relation between and requirements for the additional options will be
      vfio bus driver dependent, however unknown or unused option within this
      schema should return error.  This allow for future use of unknown
      options as well as a positive indication to the user that an option is
      used.
      
      An example VF token option would take this form:
      
      "0000:03:00.0 vf_token=2ab74924-c335-45f4-9b16-8569e5b08258"
      
      When accessing a VF where the PF is making use of vfio-pci, the user
      MUST provide the current vf_token.  When accessing a PF, the user MUST
      provide the current vf_token IF there are active VF users or MAY provide
      a vf_token in order to set the current VF token when no VF users are
      active.  The former requirement assures VF users that an unassociated
      driver cannot usurp the PF device.  These semantics also imply that a
      VF token MUST be set by a PF driver before VF drivers can access their
      device, the default token is random and mechanisms to read the token are
      not provided in order to protect the VF token of previous users.  Use of
      the vf_token option outside of these cases will return an error, as
      discussed above.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      cc20d799
    • A
      vfio/pci: Implement match ops · 467c084f
      Alex Williamson 提交于
      This currently serves the same purpose as the default implementation
      but will be expanded for additional functionality.
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Reviewed-by: NKevin Tian <kevin.tian@intel.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      467c084f
  18. 14 10月, 2019 1 次提交
  19. 23 8月, 2019 1 次提交
  20. 19 6月, 2019 1 次提交
  21. 23 4月, 2019 1 次提交
  22. 04 4月, 2019 1 次提交
    • L
      vfio/pci: use correct format characters · 426b046b
      Louis Taylor 提交于
      When compiling with -Wformat, clang emits the following warnings:
      
      drivers/vfio/pci/vfio_pci.c:1601:5: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                      ^~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1601:13: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                              ^~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1601:21: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                                      ^~~~~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1601:32: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                                                 ^~~~~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1605:5: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                      ^~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1605:13: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                              ^~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1605:21: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                                      ^~~~~~~~~
      
      drivers/vfio/pci/vfio_pci.c:1605:32: warning: format specifies type
            'unsigned short' but the argument has type 'unsigned int' [-Wformat]
                                      vendor, device, subvendor, subdevice,
                                                                 ^~~~~~~~~
      The types of these arguments are unconditionally defined, so this patch
      updates the format character to the correct ones for unsigned ints.
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/378Signed-off-by: NLouis Taylor <louis@kragniz.eu>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      426b046b