100 Commits
Author SHA1 Message Date
Alex Williamson 79b1d6caec vfio: Dump migration features under debugfs
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 451bb96328981808463405d436bd58de16dd967d
Author: Cédric Le Goater <clg@redhat.com>
Date:   Thu Sep 18 14:19:28 2025 +0200

    vfio: Dump migration features under debugfs

    A debugfs directory was recently added for VFIO devices. Add a new
    "features" file under the migration sub-directory to expose which
    features the device supports.

    Signed-off-by: Cédric Le Goater <clg@redhat.com>
    Link: https://lore.kernel.org/r/20250918121928.1921871-1-clg@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson 01e698581c vfio/type1: optimize vfio_unpin_pages_remote()
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit d14de5b92578c769e12d84c9bdeee5627c042270
Author: Li Zhe <lizhe.67@bytedance.com>
Date:   Thu Aug 14 14:47:14 2025 +0800

    vfio/type1: optimize vfio_unpin_pages_remote()

    When vfio_unpin_pages_remote() is called with a range of addresses that
    includes large folios, the function currently performs individual
    put_pfn() operations for each page. This can lead to significant
    performance overheads, especially when dealing with large ranges of pages.

    It would be very rare for reserved PFNs and non reserved will to be mixed
    within the same range. So this patch utilizes the has_rsvd variable
    introduced in the previous patch to determine whether batch put_pfn()
    operations can be performed. Moreover, compared to put_pfn(),
    unpin_user_page_range_dirty_lock() is capable of handling large folio
    scenarios more efficiently.

    The performance test results for completing the 16G VFIO IOMMU DMA
    unmapping are as follows.

    Base(v6.16):
    ------- AVERAGE (MADV_HUGEPAGE) --------
    VFIO UNMAP DMA in 0.141 s (113.7 GB/s)
    ------- AVERAGE (MAP_POPULATE) --------
    VFIO UNMAP DMA in 0.307 s (52.2 GB/s)
    ------- AVERAGE (HUGETLBFS) --------
    VFIO UNMAP DMA in 0.135 s (118.6 GB/s)

    With this patchset:
    ------- AVERAGE (MADV_HUGEPAGE) --------
    VFIO UNMAP DMA in 0.044 s (363.2 GB/s)
    ------- AVERAGE (MAP_POPULATE) --------
    VFIO UNMAP DMA in 0.289 s (55.3 GB/s)
    ------- AVERAGE (HUGETLBFS) --------
    VFIO UNMAP DMA in 0.044 s (361.3 GB/s)

    For large folio, we achieve an over 67% performance improvement in
    the VFIO UNMAP DMA item. For small folios, the performance test
    results appear to show a slight improvement.

    Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
    Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Acked-by: David Hildenbrand <david@redhat.com>
    Link: https://lore.kernel.org/r/20250814064714.56485-6-lizhe.67@bytedance.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson b614857aa6 vfio/type1: introduce a new member has_rsvd for struct vfio_dma
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 089722e8939e580c9ccc64678ba22f563fdf3bb5
Author: Li Zhe <lizhe.67@bytedance.com>
Date:   Thu Aug 14 14:47:13 2025 +0800

    vfio/type1: introduce a new member has_rsvd for struct vfio_dma

    Introduce a new member has_rsvd for struct vfio_dma. This member is
    used to indicate whether there are any reserved or invalid pfns in
    the region represented by this vfio_dma. If it is true, it indicates
    that there is at least one pfn in this region that is either reserved
    or invalid.

    Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Link: https://lore.kernel.org/r/20250814064714.56485-5-lizhe.67@bytedance.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson c5a2c002b7 vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote()
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit d10872050ffeda8c3bdc08f3376bb49b34b4e643
Author: Li Zhe <lizhe.67@bytedance.com>
Date:   Thu Aug 14 14:47:12 2025 +0800

    vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote()

    The function vpfn_pages() can help us determine the number of vpfn
    nodes on the vpfn rb tree within a specified range. This allows us
    to avoid searching for each vpfn individually in the function
    vfio_unpin_pages_remote(). This patch batches the vfio_find_vpfn()
    calls in function vfio_unpin_pages_remote().

    Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
    Link: https://lore.kernel.org/r/20250814064714.56485-4-lizhe.67@bytedance.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson b10d8f310e vfio/type1: optimize vfio_pin_pages_remote()
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit f6c84a52cc41e2aaed0d956d0a1c1802513a239c
Author: Li Zhe <lizhe.67@bytedance.com>
Date:   Thu Aug 14 14:47:11 2025 +0800

    vfio/type1: optimize vfio_pin_pages_remote()

    When vfio_pin_pages_remote() is called with a range of addresses that
    includes large folios, the function currently performs individual
    statistics counting operations for each page. This can lead to significant
    performance overheads, especially when dealing with large ranges of pages.
    Batch processing of statistical counting operations can effectively enhance
    performance.

    In addition, the pages obtained through longterm GUP are neither invalid
    nor reserved. Therefore, we can reduce the overhead associated with some
    calls to function is_invalid_reserved_pfn().

    The performance test results for completing the 16G VFIO IOMMU DMA mapping
    are as follows.

    Base(v6.16):
    ------- AVERAGE (MADV_HUGEPAGE) --------
    VFIO MAP DMA in 0.049 s (328.5 GB/s)
    ------- AVERAGE (MAP_POPULATE) --------
    VFIO MAP DMA in 0.268 s (59.6 GB/s)
    ------- AVERAGE (HUGETLBFS) --------
    VFIO MAP DMA in 0.051 s (310.9 GB/s)

    With this patch:
    ------- AVERAGE (MADV_HUGEPAGE) --------
    VFIO MAP DMA in 0.025 s (629.8 GB/s)
    ------- AVERAGE (MAP_POPULATE) --------
    VFIO MAP DMA in 0.253 s (63.1 GB/s)
    ------- AVERAGE (HUGETLBFS) --------
    VFIO MAP DMA in 0.030 s (530.5 GB/s)

    For large folio, we achieve an over 40% performance improvement.
    For small folios, the performance test results indicate a
    slight improvement.

    Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
    Co-developed-by: Alex Williamson <alex.williamson@redhat.com>
    Acked-by: David Hildenbrand <david@redhat.com>
    Tested-by: Eric Farman <farman@linux.ibm.com>
    Link: https://lore.kernel.org/r/20250814064714.56485-3-lizhe.67@bytedance.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson 649a0226ed mm: introduce num_pages_contiguous()
JIRA: https://issues.redhat.com/browse/RHEL-118213
Conflicts: 56d578c1300f ("mm: convert page_to_section() to memdesc_section()")
           is not yet backported, therefore using page_to_section()

commit 929bf010e0599ddef6b640cd314f1de65dd1ca3e
Author: Li Zhe <lizhe.67@bytedance.com>
Date:   Thu Aug 14 14:47:10 2025 +0800

    mm: introduce num_pages_contiguous()

    Let's add a simple helper for determining the number of contiguous pages
    that represent contiguous PFNs.

    In an ideal world, this helper would be simpler or not even required.
    Unfortunately, on some configs we still have to maintain (SPARSEMEM
    without VMEMMAP), the memmap is allocated per memory section, and we might
    run into weird corner cases of false positives when blindly testing for
    contiguous pages only.

    One example of such false positives would be a memory section-sized hole
    that does not have a memmap. The surrounding memory sections might get
    "struct pages" that are contiguous, but the PFNs are actually not.

    This helper will, for example, be useful for determining contiguous PFNs
    in a GUP result, to batch further operations across returned "struct
    page"s. VFIO will utilize this interface to accelerate the VFIO DMA map
    process.

    Implementation based on Linus' suggestions to avoid new usage of
    nth_page() where avoidable.

    Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
    Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
    Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
    Co-developed-by: David Hildenbrand <david@redhat.com>
    Signed-off-by: David Hildenbrand <david@redhat.com>
    Link: https://lore.kernel.org/r/20250814064714.56485-2-lizhe.67@bytedance.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:37:18 -06:00
Alex Williamson 8acdf7f88d vfio/nvgrace-gpu: Add GB300 SKU to the devid table
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 407aa63018d15c35a34938633868e61174d2ef6e
Author: Tushar Dave <tdave@nvidia.com>
Date:   Thu Sep 25 12:09:35 2025 -0500

    vfio/nvgrace-gpu: Add GB300 SKU to the devid table

    GB300 is NVIDIA's Grace Blackwell Ultra Superchip.

    Add the GB300 SKU device-id to nvgrace_gpu_vfio_pci_table.

    Signed-off-by: Tushar Dave <tdave@nvidia.com>
    Reviewed-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/20250925170935.121587-1-tdave@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 35e7bcb16b vfio/pci: Fix INTx handling on legacy non-PCI 2.3 devices
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 8b9f128947dd72e0fcf256088a673abac9b720bf
Author: Timothy Pearson <tpearson@raptorengineering.com>
Date:   Tue Sep 23 12:04:33 2025 -0500

    vfio/pci: Fix INTx handling on legacy non-PCI 2.3 devices

    PCI devices prior to PCI 2.3 both use level interrupts and do not support
    interrupt masking, leading to a failure when passed through to a KVM guest on
    at least the ppc64 platform. This failure manifests as receiving and
    acknowledging a single interrupt in the guest, while the device continues to
    assert the level interrupt indicating a need for further servicing.

    When lazy IRQ masking is used on DisINTx- (non-PCI 2.3) hardware, the following
    sequence occurs:

     * Level IRQ assertion on device
     * IRQ marked disabled in kernel
     * Host interrupt handler exits without clearing the interrupt on the device
     * Eventfd is delivered to userspace
     * Guest processes IRQ and clears device interrupt
     * Device de-asserts INTx, then re-asserts INTx while the interrupt is masked
     * Newly asserted interrupt acknowledged by kernel VMM without being handled
     * Software mask removed by VFIO driver
     * Device INTx still asserted, host controller does not see new edge after EOI

    The behavior is now platform-dependent.  Some platforms (amd64) will continue
    to spew IRQs for as long as the INTX line remains asserted, therefore the IRQ
    will be handled by the host as soon as the mask is dropped.  Others (ppc64) will
    only send the one request, and if it is not handled no further interrupts will
    be sent.  The former behavior theoretically leaves the system vulnerable to
    interrupt storm, and the latter will result in the device stalling after
    receiving exactly one interrupt in the guest.

    Work around this by disabling lazy IRQ masking for DisINTx- INTx devices.

    Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
    Link: https://lore.kernel.org/r/333803015.1744464.1758647073336.JavaMail.zimbra@raptorengineeringinc.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 74eab1c81b vfio/pds: replace bitmap_free with vfree
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit acb59a4bb8ed34e738a4c3463127bf3f6b5e11a9
Author: Zilin Guan <zilin@seu.edu.cn>
Date:   Sat Sep 13 15:31:54 2025 +0000

    vfio/pds: replace bitmap_free with vfree

    host_seq_bmp is allocated with vzalloc but is currently freed with
    bitmap_free, which uses kfree internally. This mismach prevents the
    resource from being released properly and may result in memory leaks
    or other issues.

    Fix this by freeing host_seq_bmp with vfree to match the vzalloc
    allocation.

    Fixes: f232836a91 ("vfio/pds: Add support for dirty page tracking")
    Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
    Reviewed-by: Brett Creeley <brett.creeley@amd.com>
    Link: https://lore.kernel.org/r/20250913153154.1028835-1-zilin@seu.edu.cn
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 9e199733d8 vfio: return -ENOTTY for unsupported device feature
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 16df67f2189a71a8310bcebddb87ed569e8352be
Author: Alex Mastro <amastro@fb.com>
Date:   Mon Sep 8 08:58:40 2025 -0700

    vfio: return -ENOTTY for unsupported device feature

    The two implementers of vfio_device_ops.device_feature,
    vfio_cdx_ioctl_feature and vfio_pci_core_ioctl_feature, return
    -ENOTTY in the fallthrough case when the feature is unsupported. For
    consistency, the base case, vfio_ioctl_device_feature, should do the
    same when device_feature == NULL, indicating an implementation has no
    feature extensions.

    Signed-off-by: Alex Mastro <amastro@fb.com>
    Link: https://lore.kernel.org/r/20250908-vfio-enotty-v1-1-4428e1539e2e@fb.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson c9d97c980c hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit eaba58355ecd124b4a8c91df7335970ad9fe2624
Author: Miaoqian Lin <linmq006@gmail.com>
Date:   Mon Sep 1 16:18:08 2025 +0800

    hisi_acc_vfio_pci: Fix reference leak in hisi_acc_vfio_debug_init

    The debugfs_lookup() function returns a dentry with an increased reference
    count that must be released by calling dput().

    Fixes: b398f91779b8 ("hisi_acc_vfio_pci: register debugfs for hisilicon migration driver")
    Cc: stable@vger.kernel.org
    Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
    Reviewed-by: Longfang Liu <liulongfang@huawei.com>
    Link: https://lore.kernel.org/r/20250901081809.2286649-1-linmq006@gmail.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ebcea5d6e4 vfio/platform: Mark reset drivers for removal
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 801ca4ce0bce45aae1da2c8914d2f86cb68f8b55
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Mon Aug 25 11:58:01 2025 -0600

    vfio/platform: Mark reset drivers for removal

    While vfio-platform itself is on a reprieve from being removed[1],
    these reset drivers don't support any current hardware, are not being
    tested, and suggest a level of support that doesn't really exist.
    Mark them for removal to surface any remaining user such that we can
    potentially drop them and simplify the code if none appear.

    Link: https://lore.kernel.org/all/20250806170314.3768750-3-alex.williamson@redhat.com [1]
    Reviewed-by: Pranjal Shrivastava <praan@google.com>
    Reviewed-by: Mostafa Saleh <smostafa@google.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20250825175807.3264083-3-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ecf2b1d0a1 vfio/amba: Mark for removal
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit fd0f75308bfde358e39b0ebd25a50750b6139ae5
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Mon Aug 25 11:58:00 2025 -0600

    vfio/amba: Mark for removal

    vfio-amba has only been touched to keep up with the rest of the code
    base for the past 10 years.  We have no basis to believe that it's
    currently tested or used.  Mark it for deprecation.

    Reviewed-by: Pranjal Shrivastava <praan@google.com>
    Reviewed-by: Mostafa Saleh <smostafa@google.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20250825175807.3264083-2-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 8c0c8419cf MAINTAINERS: Add myself as VFIO-platform reviewer
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 08fb9897f75719947303acfb23b8c41039118a2d
Author: Pranjal Shrivastava <praan@google.com>
Date:   Mon Sep 1 19:16:19 2025 +0000

    MAINTAINERS: Add myself as VFIO-platform reviewer

    While my work at Google Cloud focuses on various areas of the kernel,
    my background in IOMMU and the VFIO subsystem motivates me to help with
    the maintenance effort for vfio-platform (based on the discussion [1])
    and ensure its continued health.

    Link: https://lore.kernel.org/all/aKxpyyKvYcd84Ayi@google.com/ [1]
    Signed-off-by: Pranjal Shrivastava <praan@google.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20250901191619.183116-1-praan@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson d7af3d4384 MAINTAINERS: Add myself as VFIO-platform reviewer
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 6dbcc6ed4bd340f96fde4335a901d985401dd45b
Author: Mostafa Saleh <smostafa@google.com>
Date:   Wed Aug 20 20:31:02 2025 +0000

    MAINTAINERS: Add myself as VFIO-platform reviewer

    Based on discussion:
    https://lore.kernel.org/kvm/20250806170314.3768750-3-alex.williamson@redhat.com/

    I will start looking into adding support for modern HW and more
    features to VFIO-platform.

    Signed-off-by: Mostafa Saleh <smostafa@google.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20250820203102.2034333-1-smostafa@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ade9868774 docs: proc.rst: Fix VFIO Device title formatting
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 093458c58f830d0a713fab0de037df5f0ce24fef
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Thu Aug 28 14:36:24 2025 -0600

    docs: proc.rst: Fix VFIO Device title formatting

    Title underline is one character too short.

    Cc: Alex Mastro <amastro@fb.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Closes: https://lore.kernel.org/all/20250828123035.2f0c74e7@canb.auug.org.au
    Fixes: 1e736f148956 ("vfio/pci: print vfio-device syspath to fdinfo")
    Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
    Link: https://lore.kernel.org/r/20250828203629.283418-1-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson e655b105d3 vfio: selftests: Fix .gitignore for already tracked files
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 03e073bc4dbc3d64ce0beb21fbe793ae7787e062
Author: David Matlack <dmatlack@google.com>
Date:   Thu Aug 28 18:58:14 2025 +0000

    vfio: selftests: Fix .gitignore for already tracked files

    Fix the rules in tools/testing/selftests/vfio/.gitignore to not ignore
    some already tracked files (.gitignore, Makefile, lib/libvfio.mk).

    This change should be a no-op, since these files are already tracked by git
    and thus git will not ignore updates to them even though they match the
    ignore rules in the VFIO selftests .gitignore file.

    However, they do generate warnings with W=1, as reported by the kernel test
    robot.

      $ KBUILD_EXTRA_WARN=1 scripts/misc-check
      tools/testing/selftests/vfio/.gitignore: warning: ignored by one of the .gitignore files
      tools/testing/selftests/vfio/Makefile: warning: ignored by one of the .gitignore files
      tools/testing/selftests/vfio/lib/libvfio.mk: warning: ignored by one of the .gitignore files

    Fix this by explicitly un-ignoring the tracked files.

    Fixes: 292e9ee22b0a ("selftests: Create tools/testing/selftests/vfio")
    Reported-by: kernel test robot <lkp@intel.com>
    Closes: https://lore.kernel.org/oe-kbuild-all/202508280918.rFRyiLEU-lkp@intel.com/
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250828185815.382215-1-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson cfd468f715 MAINTAINERS: Update Shameer Kolothum's email address
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit fcf9ae9ec9761802b69294d1b3f98d51f14e5175
Author: Shameer Kolothum <skolothumtho@nvidia.com>
Date:   Wed Aug 27 15:32:15 2025 +0100

    MAINTAINERS: Update Shameer Kolothum's email address

    Changed jobs and Huawei email is no longer valid.

    Also, since I no longer have access to HiSilicon hardware,
    remove myself from HISILICON PCI DRIVER maintainer entry.

    Acked-by: Jonathan Cameron <jonathan.cameron@huawei.com>
    Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
    Link: https://lore.kernel.org/r/20250827143215.2311-1-skolothumtho@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 31a76ef040 vfio: selftests: Add a script to help with running VFIO selftests
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit fd134b0f2f8ef9b1b7b0cade8cac4ff831619713
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:17 2025 +0000

    vfio: selftests: Add a script to help with running VFIO selftests

    Introduce run.sh, a script to help with running VFIO selftests. The
    script is intended to be used for both humans manually running VFIO
    selftests, and to incorporate into test automation where VFIO selftests
    may run alongside other tests. As such the script aims to be hermetic,
    returning the system to the state it was before the test started.

    The script takes as input the BDF of a device to use and a command to
    run (typically the command would be a VFIO selftest). e.g.

      $ ./run.sh -d 0000:6a:01.0 ./vfio_pci_device_test

     or

      $ ./run.sh -d 0000:6a:01.0 -- ./vfio_pci_device_test

    The script then handles unbinding device 0000:6a:01.0 from its current
    driver, binding it to vfio-pci, running the test, unbinding from
    vfio-pci, and binding back to the original driver.

    When run.sh runs the provided test, it does so by appending the BDF as
    the last parameter. For example:

      $ ./run.sh -d 0000:6a:01.0 -- echo hello

    Results in the following being printed to stdout:

      hello 0000:6a:01.0

    The script also supports a mode where it can break out into a shell so
    that multiple tests can be run manually.

      $ ./run.sh -d 0000:6a:01.0 -s
      $ echo $VFIO_SELFTESTS_BDF
      $ ./vfio_pci_device_test
      $ exit

    Choosing which device to use is up to the user.

    In the future this script should be extensible to tests that want to use
    multiple devices. The script can support accepting -d BDF multiple times
    and parse them into an array, setup all the devices, pass the list of
    BDFs to the test, and then cleanup all the devices.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-31-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 132488187a vfio: selftests: Make iommufd the default iommu_mode
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 8afcbe20476ad238fd1f331f51d721138eff5172
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:16 2025 +0000

    vfio: selftests: Make iommufd the default iommu_mode

    Now that VFIO selftests support iommufd, make it the default mode.
    IOMMUFD is the successor to VFIO_TYPE1{,v2}_IOMMU and all new features
    are being added there, so it's a slightly better fit as the default
    mode.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-30-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ca1581cb2d vfio: selftests: Add iommufd mode
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 61cbfe5014cbc17b376b6a9b2087f39f379a6b86
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:15 2025 +0000

    vfio: selftests: Add iommufd mode

    Add a new IOMMU mode for using iommufd directly. In this mode userspace
    opens /dev/iommu and binds it to a device FD acquired through
    /dev/vfio/devices/vfioX.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-29-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 814b8f6788 vfio: selftests: Add iommufd_compat_type1{,v2} modes
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit d1a17495bb878542898d7ca4aa8fde29423a8ee0
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:14 2025 +0000

    vfio: selftests: Add iommufd_compat_type1{,v2} modes

    Add new IOMMU modes for using iommufd in compatibility mode with
    VFIO_TYPE1_IOMMU and VFIO_TYPE1v2_IOMMU.

    In these modes, VFIO selftests will open /dev/iommu and treats it as a
    container FD (as if it had opened /dev/vfio/vfio) and the kernel
    translates the container ioctls to iommufd calls transparently.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-28-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson bf80a4ebc6 vfio: selftests: Add vfio_type1v2_mode
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 0969c685ba5b248648533a3313f55a3fd9382a9e
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:13 2025 +0000

    vfio: selftests: Add vfio_type1v2_mode

    Add a new IOMMU mode for using VFIO_TYPE1v2_IOMMU.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-27-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 24e773c1f0 vfio: selftests: Replicate tests across all iommu_modes
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 892aff147a545fa7c94d98613093afa84faa25b1
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:12 2025 +0000

    vfio: selftests: Replicate tests across all iommu_modes

    Automatically replicate vfio_dma_mapping_test and vfio_pci_driver_test
    across all supported IOMMU modes using fixture variants. Both of these
    tests exercise DMA mapping to some degree so having automatic coverage
    across all IOMMU modes will help catch bugs.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-26-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 911d27b529 vfio: selftests: Encapsulate IOMMU mode
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 5df9bd6205114fac04c0f9539fa23f996e22a439
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:11 2025 +0000

    vfio: selftests: Encapsulate IOMMU mode

    Encapsulate the "IOMMU mode" a test should use behind a new struct.
    In the future this will be used to support other types of IOMMUs besides
    VFIO_TYPE1_IOMMU, and allow users to select the mode on the command
    line.

    No functional change intended.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-25-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 625895940e vfio: selftests: Move helper to get cdev path to libvfio
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 118e073ef6a3446862ada27bdca2b8a53447f428
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:10 2025 +0000

    vfio: selftests: Move helper to get cdev path to libvfio

    Move the helper function to get the VFIO cdev path to libvfio so that it
    can be used in libvfio in a subsequent commit.

    No functional change intended.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-24-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 2649951731 vfio: selftests: Add driver for Intel DSA
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 35b05bd96204bc40a2ca8620bad1a5d139c20060
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:09 2025 +0000

    vfio: selftests: Add driver for Intel DSA

    Add a driver to VFIO selftests for Intel DSA devices.

    For now the driver only supports up to 32 batches and 1024 copies per
    batch, which were the limits of the hardware this commit was tested
    with. This is sufficient to generate 9+ minutes of DMA memcpys at a rate
    of over 30 GB/s. This should be plenty to stress test VFIO and the IOMMU.

    The driver does not yet support requesting interrupt handles, as this
    commit was not tested against hardware that requires it.

    Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
    Cc: Dave Jiang <dave.jiang@intel.com>
    Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-23-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson a9aef9a1a9 dmaengine: idxd: Allow registers.h to be included from tools/
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 003e6faf2c8ff1670c35622f11ff6211be563a9e
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:08 2025 +0000

    dmaengine: idxd: Allow registers.h to be included from tools/

    Allow drivers/dma/idxd/registers.h to be included from userspace in
    tools/ by adjusting the include path to uapi/linux/idxd.h if __KERNEL__
    is not defined.

    A subsequent commit will use registers.h to implement a userspace driver
    for Intel DSA devices in tools/testing/selftests/vfio.

    Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-22-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 21157d4f09 tools headers: Import iosubmit_cmds512()
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 3fe305773bbeb2d946b9fb3c1224c8b00d6755ef
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:07 2025 +0000

    tools headers: Import iosubmit_cmds512()

    Import iosubmit_cmds512() from arch/x86/include/asm/io.h into tools/ so
    it can be used by VFIO selftests to interact with Intel DSA devices.

    Also pull in movdir64b() from arch/x86/include/asm/special_insns.h into
    tools/, which is the underlying instruction used by iosubmit_cmds512().

    Changes made when importing: None

    Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-21-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 0cc7f78127 vfio: selftests: Add driver for Intel CBDMA
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 2223587df5c5e935cc6f973f62a9608eef81bec8
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:06 2025 +0000

    vfio: selftests: Add driver for Intel CBDMA

    Add a driver for the Intel CBDMA device. This driver is based on and
    named after the Linux driver for this device (drivers/dma/ioat/) and
    also based on previous work from Peter Shier <pshier@google.com>.

    The driver aims to be as simple as possible. It uses a single descriptor
    to issue DMA operations, and only supports the copy operation. For "DMA
    storms", the driver kicks off the maximum number of maximum-sized DMA
    operations. On Skylake server parts, this was 2^16-1 copies of size 2M
    and lasts about 15 seconds.

    Create symlinks to drivers/dma/ioat/{hw.h,registers.h} to get access to
    various macros (e.g. IOAT_CHANCMD_RESET) and struct ioat_dma_descriptor.

    Cc: Dave Jiang <dave.jiang@intel.com>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Acked-by: Dave Jiang <dave.jiang@intel.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-20-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson c1aedf3ffd dmaengine: ioat: Move system_has_dca_enabled() to dma.h
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit b7f086912c1d3ce1e8c2753e0ff329947219d0f6
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:05 2025 +0000

    dmaengine: ioat: Move system_has_dca_enabled() to dma.h

    Move the function prototype for system_has_dca_enabled() from hw.h to
    dma.h. This allows hw.h to be included from tools/, which will be used
    in a subsysequent commit to implement a userspace driver for Intel CBDMA
    devices in tools/testing/selftests/vfio.

    No functional change intended.

    Acked-by: Dave Jiang <dave.jiang@intel.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-19-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ed8ed840f3 tools headers: Add symlink to linux/pci_ids.h
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit dc0e216cf00b74cf61fdc882f8373beb8cdbec5e
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:04 2025 +0000

    tools headers: Add symlink to linux/pci_ids.h

    Add a symlink to include/linux/pci_ids.h to tools/include/. This will be
    used by VFIO selftests in subsequent commits to match device and vendor
    IDs.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-18-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson c6226eaf30 tools headers: Import x86 MMIO helper overrides
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit ce5dc9aa72d9c3d6cb14b3a6aab900124999d8d0
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:03 2025 +0000

    tools headers: Import x86 MMIO helper overrides

    Import the x86-specific overrides for <asm-generic/io.h> from the kernel
    headers into tools/include/.

    Changes made when importing:
     - Replace CONFIG_X86_64 with __x86_64__.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-17-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 025912a411 tools headers: Import asm-generic MMIO helpers
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1f9c8edd6a7e9b0fd914cfeef8ce075307e8e702
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:02 2025 +0000

    tools headers: Import asm-generic MMIO helpers

    Import the asm-generic MMIO helper functions from the kernel headers
    into tools/include/. The top-level include is <linux/io.h> which then
    includes the arch-specific <asm/io.h>, which then includes
    <asm-generic/io.h>. This layout is chosen to match the kernel header
    layout and to appease checkpatch.pl (which warns against including
    <asm/io.h> or <asm-generic/io.h> directly).

    Changes made when importing:

     - Add missing includes at the top.
     - Stub out mmiowb_set_pending().
     - Stub out _THIS_IP_.
     - Stub out log_*_mmio() calls.
     - Drop the CONFIG_64BIT checks, since tools/include/linux/types.h
       always defines u64.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-16-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 01d6a3614b tools headers: Add stub definition for __iomem
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 9bf9b185e3ce76c9fddb4c6edb0ec3334b7649df
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:01 2025 +0000

    tools headers: Add stub definition for __iomem

    Add an empty definition for __iomem so that kernel headers that use
    __iomem can be imported into tools/include/ with less modifications.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-15-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 6f95597a96 vfio: sefltests: Add vfio_pci_driver_test
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit fded8da4bc38df6e1475ac5998934c490b96215d
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:25:00 2025 +0000

    vfio: sefltests: Add vfio_pci_driver_test

    Add a new selftest that tests all driver operations. This test serves
    both as a demonstration of the driver framework, and also as a
    correctness test for future drivers.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-14-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 3bb0bc1b9e vfio: selftests: Add driver framework
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1b197032ac58b9a17350c086fc151390f32080b2
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:59 2025 +0000

    vfio: selftests: Add driver framework

    Add a driver framework to VFIO selftests, so that devices can generate
    DMA and interrupts in a common way that can be then utilized by tests.
    This will enable VFIO selftests to exercise real hardware DMA and
    interrupt paths, without needing any device-specific code in the test
    itself.

    Subsequent commits will introduce drivers for specific devices.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-13-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 49e0c15bcd vfio: selftests: Add a helper for matching vendor+device IDs
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 50d8fe805f75a159551ddb6b04ecdad26ec50221
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:58 2025 +0000

    vfio: selftests: Add a helper for matching vendor+device IDs

    Add a helper function for matching a device against a given vendor and
    device ID. This will be used in a subsequent commit to match devices
    against drivers.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-12-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 0d0a600494 vfio: selftests: Enable asserting MSI eventfds not firing
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 924947804f2b9e564efdc814420d21b239df2dd4
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:57 2025 +0000

    vfio: selftests: Enable asserting MSI eventfds not firing

    Make it possible to assert that a given MSI eventfd did _not_ fire by
    adding a helper to mark an eventfd non-blocking. Demonstrate this in
    vfio_pci_device_test by asserting the MSI eventfd did not fire before
    vfio_pci_irq_trigger().

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-11-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 2d598f5902 vfio: selftests: Keep track of DMA regions mapped into the device
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 346cd58f1fb588f8ff193d76cf0bb455446ace03
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:56 2025 +0000

    vfio: selftests: Keep track of DMA regions mapped into the device

    Keep track of the list of DMA regions that are mapped into the device
    using a linked list and a new struct vfio_dma_region and use that to add
    {__,}to_iova() for converting host virtual addresses into IOVAs.

    This will be used in a subsequent commit to map multiple DMA regions
    into a device that are then used by drivers.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-10-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 04cee24f7c vfio: selftests: Validate 2M/1G HugeTLB are mapped as 2M/1G in IOMMU
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 47f861048ef7034a59431020c5916a43378a8c0c
Author: Josh Hilke <jrhilke@google.com>
Date:   Fri Aug 22 21:24:55 2025 +0000

    vfio: selftests: Validate 2M/1G HugeTLB are mapped as 2M/1G in IOMMU

    Update vfio dma mapping test to verify that the IOMMU uses 2M and 1G
    mappings when 2M and 1G HugeTLB pages are mapped into a device
    respectively.

    This validation is done by inspecting the contents of the I/O page
    tables via /sys/kernel/debug/iommu/intel/. This validation is skipped if
    that directory is not available (i.e. non-Intel IOMMUs).

    Signed-off-by: Josh Hilke <jrhilke@google.com>
    [reword commit message, refactor code]
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-9-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 25e8b55cfd vfio: selftests: Add DMA mapping tests for 2M and 1G HugeTLB
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 751f6b5d06c301b329b699ab2089c9dcb7eebc47
Author: Josh Hilke <jrhilke@google.com>
Date:   Fri Aug 22 21:24:54 2025 +0000

    vfio: selftests: Add DMA mapping tests for 2M and 1G HugeTLB

    Add test coverage of mapping 2M and 1G HugeTLB to vfio_dma_mapping_test
    using a fixture variant. If there isn't enough HugeTLB memory available
    for the test, just skip them.

    Signed-off-by: Josh Hilke <jrhilke@google.com>
    [switch from command line option to fixture variant]
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-8-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 9492fee1a0 vfio: selftests: Add test to reset vfio device.
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit a0fd0af504f7fe11e2f87e48a1924d7e7f5a0590
Author: Josh Hilke <jrhilke@google.com>
Date:   Fri Aug 22 21:24:53 2025 +0000

    vfio: selftests: Add test to reset vfio device.

    Add a test to vfio_pci_device_test which resets the device. If reset is
    not supported by the device, the test is skipped.

    Signed-off-by: Josh Hilke <jrhilke@google.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-7-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 61de0f76bb vfio: selftests: Move vfio dma mapping test to their own file
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit b477e7bcd25ecb4da91bb52d5f980611cc77d543
Author: Josh Hilke <jrhilke@google.com>
Date:   Fri Aug 22 21:24:52 2025 +0000

    vfio: selftests: Move vfio dma mapping test to their own file

    Move the dma_map_unmap test from vfio_pci_device_test to a new test:
    vfio_dma_mapping_test. We are going to add more complex dma mapping
    tests, so it makes sense to separate this from the vfio pci device
    test which is more of a sanity check for vfio pci functionality.

    Signed-off-by: Josh Hilke <jrhilke@google.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-6-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 81ba605828 vfio: selftests: Test basic VFIO and IOMMUFD integration
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 790588f06e9ce58c281faeada453f47361bc06b6
Author: Josh Hilke <jrhilke@google.com>
Date:   Fri Aug 22 21:24:51 2025 +0000

    vfio: selftests: Test basic VFIO and IOMMUFD integration

    Add a vfio test suite which verifies that userspace can bind and unbind
    devices, allocate I/O address space, and attach a device to an IOMMU
    domain using the cdev + IOMMUfd VFIO interface.

    Signed-off-by: Josh Hilke <jrhilke@google.com>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-5-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson f6fd261a3c vfio: selftests: Introduce vfio_pci_device_test
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 16eadd7c1277284cfff5b7071910920a2d008251
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:50 2025 +0000

    vfio: selftests: Introduce vfio_pci_device_test

    Introduce a basic VFIO selftest called vfio_pci_device_test to
    demonstrate the functionality of the VFIO selftest library and provide
    some test coverage of basic VFIO operations, including:

     - Mapping and unmapping DMA
     - Mapping and unmapping BARs
     - Enabling, triggering, and disabling MSI and MSI-x
     - Reading and writing to PCI config space

    This test should work with most PCI devices, as long as they are bound
    to vfio-pci.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-4-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson edc5d665fb vfio: selftests: Add a helper library for VFIO selftests
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 19faf6fd969c21589b6dd40c35255e4d00d427f8
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:49 2025 +0000

    vfio: selftests: Add a helper library for VFIO selftests

    Add a basic helper library to be used by VFIO selftests.

    The basic unit of the library is struct vfio_pci_device, which
    represents a single PCI device that is bound to the vfio-pci driver. The
    library currently only supports a single device per group and container,
    and VFIO IOMMU types.

    The code in this library was heavily based on prior work done by
    Raghavendra Rao Ananta <rananta@google.com>, and the VFIO_ASSERT*()
    macros were written by Vipin Sharma <vipinsh@google.com>.

    Separate that Makefile rules for building the library into a separate
    script so that the library can be built by and linked into KVM selftests
    in a subsequent commit.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-3-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 28c17bf79d selftests: Create tools/testing/selftests/vfio
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 292e9ee22b0adad49c9a6f63708988e32c007da6
Author: David Matlack <dmatlack@google.com>
Date:   Fri Aug 22 21:24:48 2025 +0000

    selftests: Create tools/testing/selftests/vfio

    Create the directory tools/testing/selftests/vfio with a stub Makefile
    and hook it up to the top-level selftests Makefile.

    This directory will be used in subsequent commits to host selftests for
    the VFIO subsystem.

    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: David Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20250822212518.4156428-2-dmatlack@google.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson a1f13f4aaa vfio/nvgrace-gpu: fix grammatical error
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 767b1ed8b980498978c77dc89497602ae3421af5
Author: Morduan Zang <zhangdandan@uniontech.com>
Date:   Thu Aug 14 19:03:58 2025 +0800

    vfio/nvgrace-gpu: fix grammatical error

    The word "as" in the comment should be replaced with "is",
    and there is an extra space in the comment.

    Signed-off-by: Morduan Zang <zhangdandan@uniontech.com>
    Reviewed-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/54E1ED6C5A2682C8+20250814110358.285412-1-zhangdandan@uniontech.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson cbb4bf5024 vfio/pci: drop redundant conversion to bool
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 473c3af395c904ad5e10897bf482a92c4f3f3650
Author: Xichao Zhao <zhao.xichao@vivo.com>
Date:   Mon Aug 18 16:52:01 2025 +0800

    vfio/pci: drop redundant conversion to bool

    The result of integer comparison already evaluates to bool. No need for
    explicit conversion.

    No functional impact.

    Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
    Link: https://lore.kernel.org/r/20250818085201.510206-1-zhao.xichao@vivo.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 4947916136 vfio/fsl-mc: Mark for removal
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1b1d9ca13475cbedf25727ae4b4ead684ae85c03
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Wed Aug 6 11:03:11 2025 -0600

    vfio/fsl-mc: Mark for removal

    The driver has been orphaned for more than a year, mark it for removal.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Cédric Le Goater <clg@redhat.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20250806170314.3768750-2-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson c4dd903c66 vfio/pci: print vfio-device syspath to fdinfo
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1e736f1489563470b58ede3fae5274a624280cf1
Author: Alex Mastro <amastro@fb.com>
Date:   Mon Aug 4 12:44:31 2025 -0700

    vfio/pci: print vfio-device syspath to fdinfo

    Print the PCI device syspath to a vfio device's fdinfo. This enables tools
    to query which device is associated with a given vfio device fd.

    This results in output like below:

    $ cat /proc/"$SOME_PID"/fdinfo/"$VFIO_FD" | grep vfio
    vfio-device-syspath: /sys/devices/pci0000:e0/0000:e0:01.1/0000:e1:00.0/0000:e2:05.0/0000:e8:00.0

    Signed-off-by: Alex Mastro <amastro@fb.com>
    Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
    Tested-by: Amit Machhiwal <amachhiw@linux.ibm.com>
    Link: https://lore.kernel.org/r/20250804-show-fdinfo-v4-1-96b14c5691b3@fb.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson a16aa1e711 vfio/type1: conditional rescheduling while pinning
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit b1779e4f209c7ff7e32f3c79d69bca4e3a3a68b6
Author: Keith Busch <kbusch@kernel.org>
Date:   Tue Jul 15 11:46:22 2025 -0700

    vfio/type1: conditional rescheduling while pinning

    A large DMA mapping request can loop through dma address pinning for
    many pages. In cases where THP can not be used, the repeated vmf_insert_pfn can
    be costly, so let the task reschedule as need to prevent CPU stalls. Failure to
    do so has potential harmful side effects, like increased memory pressure
    as unrelated rcu tasks are unable to make their reclaim callbacks and
    result in OOM conditions.

     rcu: INFO: rcu_sched self-detected stall on CPU
     rcu:   36-....: (20999 ticks this GP) idle=b01c/1/0x4000000000000000 softirq=35839/35839 fqs=3538
     rcu:            hardirqs   softirqs   csw/system
     rcu:    number:        0        107            0
     rcu:   cputime:       50          0        10446   ==> 10556(ms)
     rcu:   (t=21075 jiffies g=377761 q=204059 ncpus=384)
    ...
      <TASK>
      ? asm_sysvec_apic_timer_interrupt+0x16/0x20
      ? walk_system_ram_range+0x63/0x120
      ? walk_system_ram_range+0x46/0x120
      ? pgprot_writethrough+0x20/0x20
      lookup_memtype+0x67/0xf0
      track_pfn_insert+0x20/0x40
      vmf_insert_pfn_prot+0x88/0x140
      vfio_pci_mmap_huge_fault+0xf9/0x1b0 [vfio_pci_core]
      __do_fault+0x28/0x1b0
      handle_mm_fault+0xef1/0x2560
      fixup_user_fault+0xf5/0x270
      vaddr_get_pfns+0x169/0x2f0 [vfio_iommu_type1]
      vfio_pin_pages_remote+0x162/0x8e0 [vfio_iommu_type1]
      vfio_iommu_type1_ioctl+0x1121/0x1810 [vfio_iommu_type1]
      ? futex_wake+0x1c1/0x260
      x64_sys_call+0x234/0x17a0
      do_syscall_64+0x63/0x130
      ? exc_page_fault+0x63/0x130
      entry_SYSCALL_64_after_hwframe+0x4b/0x53

    Signed-off-by: Keith Busch <kbusch@kernel.org>
    Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
    Link: https://lore.kernel.org/r/20250715184622.3561598-1-kbusch@meta.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 5e89cbed52 vfio/qat: add support for intel QAT 6xxx virtual functions
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1e9c0f1da562651160456e45629f815673c2dd5e
Author: Małgorzata Mielnik <malgorzata.mielnik@intel.com>
Date:   Tue Jul 15 09:11:50 2025 +0100

    vfio/qat: add support for intel QAT 6xxx virtual functions

    Extend the qat_vfio_pci variant driver to support QAT 6xxx Virtual
    Functions (VFs). Add the relevant QAT 6xxx VF device IDs to the driver's
    probe table, enabling proper detection and initialization of these devices.

    Update the module description to reflect that the driver now supports all
    QAT generations.

    Signed-off-by: Małgorzata Mielnik <malgorzata.mielnik@intel.com>
    Signed-off-by: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>
    Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
    Link: https://lore.kernel.org/r/20250715081150.1244466-1-suman.kumar.chakraborty@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson cb042af763 vfio/qat: Remove myself from VFIO QAT PCI driver maintainers
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 27a23faecd5f62c8fea86c5aa67479b559306406
Author: Xin Zeng <xin.zeng@intel.com>
Date:   Mon Jul 14 20:13:57 2025 -0400

    vfio/qat: Remove myself from VFIO QAT PCI driver maintainers

    Remove myself from VFIO QAT PCI driver maintainers as I'm leaving
    Intel.

    Signed-off-by: Xin Zeng <xin.zeng@intel.com>
    Link: https://lore.kernel.org/r/20250715001357.33725-1-xin.zeng@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 833b09038c vfio/pci: Do vf_token checks for VFIO_DEVICE_BIND_IOMMUFD
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 86624ba3b522b6512def25534341da93356c8da4
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date:   Mon Jul 14 13:08:25 2025 -0300

    vfio/pci: Do vf_token checks for VFIO_DEVICE_BIND_IOMMUFD

    This was missed during the initial implementation. The VFIO PCI encodes
    the vf_token inside the device name when opening the device from the group
    FD, something like:

      "0000:04:10.0 vf_token=bd8d9d2b-5a5f-4f5a-a211-f591514ba1f3"

    This is used to control access to a VF unless there is co-ordination with
    the owner of the PF.

    Since we no longer have a device name in the cdev path, pass the token
    directly through VFIO_DEVICE_BIND_IOMMUFD using an optional field
    indicated by VFIO_DEVICE_BIND_FLAG_TOKEN.

    Fixes: 5fcc26969a ("vfio: Add VFIO_DEVICE_BIND_IOMMUFD")
    Tested-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Reviewed-by: Yi Liu <yi.l.liu@intel.com>
    Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Link: https://lore.kernel.org/r/0-v3-bdd8716e85fe+3978a-vfio_token_jgg@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 11789a1093 vfio/mlx5: fix possible overflow in tracking max message size
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit b3060198483bac43ec113c62ae3837076f61f5de
Author: Artem Sadovnikov <a.sadovnikov@ispras.ru>
Date:   Tue Jul 1 14:40:17 2025 +0000

    vfio/mlx5: fix possible overflow in tracking max message size

    MLX cap pg_track_log_max_msg_size consists of 5 bits, value of which is
    used as power of 2 for max_msg_size. This can lead to multiplication
    overflow between max_msg_size (u32) and integer constant, and afterwards
    incorrect value is being written to rq_size.

    Fix this issue by extending integer constant to u64 type.

    Found by Linux Verification Center (linuxtesting.org) with SVACE.

    Suggested-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Artem Sadovnikov <a.sadovnikov@ispras.ru>
    Reviewed-by: Yishai Hadas <yishaih@nvidia.com>
    Link: https://lore.kernel.org/r/20250701144017.2410-2-a.sadovnikov@ispras.ru
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 8a960c0260 vfio/pci: Separate SR-IOV VF dev_set
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit e908f58b6beb337cbe4481d52c3f5c78167b1aab
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Thu Jun 26 16:56:18 2025 -0600

    vfio/pci: Separate SR-IOV VF dev_set

    In the below noted Fixes commit we introduced a reflck mutex to allow
    better scaling between devices for open and close.  The reflck was
    based on the hot reset granularity, device level for root bus devices
    which cannot support hot reset or bus/slot reset otherwise.  Overlooked
    in this were SR-IOV VFs, where there's also no bus reset option, but
    the default for a non-root-bus, non-slot-based device is bus level
    reflck granularity.

    The reflck mutex has since become the dev_set mutex (via commit
    2cd8b14aaa ("vfio/pci: Move to the device set infrastructure")) and
    is our defacto serialization for various operations and ioctls.  It
    still seems to be the case though that sets of vfio-pci devices really
    only need serialization relative to hot resets affecting the entire
    set, which is not relevant to SR-IOV VFs.  As described in the Closes
    link below, this serialization contributes to startup latency when
    multiple VFs sharing the same "bus" are opened concurrently.

    Mark the device itself as the basis of the dev_set for SR-IOV VFs.

    Reported-by: Aaron Lewis <aaronlewis@google.com>
    Closes: https://lore.kernel.org/all/20250626180424.632628-1-aaronlewis@google.com
    Tested-by: Aaron Lewis <aaronlewis@google.com>
    Fixes: e309df5b0c ("vfio/pci: Parallelize device open and release")
    Reviewed-by: Yi Liu <yi.l.liu@intel.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20250626225623.1180952-1-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 47b3a8e4b0 vfio/pds: Fix missing detach_ioas op
JIRA: https://issues.redhat.com/browse/RHEL-118213
CVE: CVE-2025-38625

commit fe24d5bc635e103a517ec201c3cb571eeab8be2f
Author: Brett Creeley <brett.creeley@amd.com>
Date:   Wed Jul 2 09:37:44 2025 -0700

    vfio/pds: Fix missing detach_ioas op

    When CONFIG_IOMMUFD is enabled and a device is bound to the pds_vfio_pci
    driver, the following WARN_ON() trace is seen and probe fails:

    WARNING: CPU: 0 PID: 5040 at drivers/vfio/vfio_main.c:317 __vfio_register_dev+0x130/0x140 [vfio]
    <...>
    pds_vfio_pci 0000:08:00.1: probe with driver pds_vfio_pci failed with error -22

    This is because the driver's vfio_device_ops.detach_ioas isn't set.

    Fix this by using the generic vfio_iommufd_physical_detach_ioas
    function.

    Fixes: 38fe3975b4 ("vfio/pds: Initial support for pds VFIO driver")
    Signed-off-by: Brett Creeley <brett.creeley@amd.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Link: https://lore.kernel.org/r/20250702163744.69767-1-brett.creeley@amd.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson ab5ccb6a68 vfio: Prevent open_count decrement to negative
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 982ddd59ed97dc7e63efd97ed50273ffb817bd41
Author: Jacob Pan <jacob.pan@linux.microsoft.com>
Date:   Wed Jun 18 16:46:18 2025 -0700

    vfio: Prevent open_count decrement to negative

    When vfio_df_close() is called with open_count=0, it triggers a warning in
    vfio_assert_device_open() but still decrements open_count to -1. This allows
    a subsequent open to incorrectly pass the open_count == 0 check, leading to
    unintended behavior, such as setting df->access_granted = true.

    For example, running an IOMMUFD compat no-IOMMU device with VFIO tests
    (https://github.com/awilliam/tests/blob/master/vfio-noiommu-pci-device-open.c)
    results in a warning and a failed VFIO_GROUP_GET_DEVICE_FD ioctl on the first
    run, but the second run succeeds incorrectly.

    Add checks to avoid decrementing open_count below zero.

    Fixes: 05f37e1c03 ("vfio: Pass struct vfio_device_file * to vfio_device_open/close()")
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Yi Liu <yi.l.liu@intel.com>
    Signed-off-by: Jacob Pan <jacob.pan@linux.microsoft.com>
    Link: https://lore.kernel.org/r/20250618234618.1910456-2-jacob.pan@linux.microsoft.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson cedc005c9c vfio: Fix unbalanced vfio_df_close call in no-iommu mode
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit b25e271b377999191b12f0afbe1861edcf57e3fe
Author: Jacob Pan <jacob.pan@linux.microsoft.com>
Date:   Wed Jun 18 16:46:17 2025 -0700

    vfio: Fix unbalanced vfio_df_close call in no-iommu mode

    For devices with no-iommu enabled in IOMMUFD VFIO compat mode, the group open
    path skips vfio_df_open(), leaving open_count at 0. This causes a warning in
    vfio_assert_device_open(device) when vfio_df_close() is called during group
    close.

    The correct behavior is to skip only the IOMMUFD bind in the device open path
    for no-iommu devices. Commit 6086efe734 omitted vfio_df_open(), which was
    too broad. This patch restores the previous behavior, ensuring
    the vfio_df_open is called in the group open path.

    Fixes: 6086efe734 ("vfio-iommufd: Move noiommu compat validation out of vfio_iommufd_bind()")
    Suggested-by: Alex Williamson <alex.williamson@redhat.com>
    Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Jacob Pan <jacob.pan@linux.microsoft.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20250618234618.1910456-1-jacob.pan@linux.microsoft.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson c33412f750 irqbypass: Require producers to pass in Linux IRQ number during registration
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 23b54381cee2928e8b5622e654ca4516f30d2f1a
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:34 2025 -0700

    irqbypass: Require producers to pass in Linux IRQ number during registration

    Pass in the Linux IRQ associated with an IRQ bypass producer instead of
    relying on the caller to set the field prior to registration, as there's
    no benefit to relying on callers to do the right thing.

    Take care to set producer->irq before __connect(), as KVM expects the IRQ
    to be valid as soon as a connection is possible.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-9-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 2ac3467eae irqbypass: Use xarray to track producers and consumers
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 8394b32faecd9c63b3c436e78e62519e9548e530
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:33 2025 -0700

    irqbypass: Use xarray to track producers and consumers

    Track IRQ bypass producers and consumers using an xarray to avoid the O(2n)
    insertion time associated with walking a list to check for duplicate
    entries, and to search for an partner.

    At low (tens or few hundreds) total producer/consumer counts, using a list
    is faster due to the need to allocate backing storage for xarray.  But as
    count creeps into the thousands, xarray wins easily, and can provide
    several orders of magnitude better latency at high counts.  E.g. hundreds
    of nanoseconds vs. hundreds of milliseconds.

    Cc: Oliver Upton <oliver.upton@linux.dev>
    Cc: David Matlack <dmatlack@google.com>
    Cc: Like Xu <like.xu.linux@gmail.com>
    Cc: Binbin Wu <binbin.wu@linux.intel.com>
    Reported-by: Yong He <alexyonghe@tencent.com>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217379
    Link: https://lore.kernel.org/all/20230801115646.33990-1-likexu@tencent.com
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-8-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 73909b9557 irqbypass: Use guard(mutex) in lieu of manual lock+unlock
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 46a4bfd0ae480cabbacc56fe0d8f91cbe229c7ce
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:32 2025 -0700

    irqbypass: Use guard(mutex) in lieu of manual lock+unlock

    Use guard(mutex) to clean up irqbypass's error handling.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-7-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 79d50d9869 irqbypass: Use paired consumer/producer to disconnect during unregister
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 5d7dbdce388b43cf3a9bc50c4132493de26aeba4
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:31 2025 -0700

    irqbypass: Use paired consumer/producer to disconnect during unregister

    Use the paired consumer/producer information to disconnect IRQ bypass
    producers/consumers in O(1) time (ignoring the cost of __disconnect()).

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-6-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 6ca5e308ce irqbypass: Explicitly track producer and consumer bindings
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit add57f493e0893ac0fb4acbdc441918d3e800f10
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:30 2025 -0700

    irqbypass: Explicitly track producer and consumer bindings

    Explicitly track IRQ bypass producer:consumer bindings.  This will allow
    making removal an O(1) operation; searching through the list to find
    information that is trivially tracked (and useful for debug) is wasteful.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-5-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 663386e945 irqbypass: Take ownership of producer/consumer token tracking
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 2b521d86ee80a436a92445b8206d38d75aeb39ea
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:29 2025 -0700

    irqbypass: Take ownership of producer/consumer token tracking

    Move ownership of IRQ bypass token tracking into irqbypass.ko, and
    explicitly require callers to pass an eventfd_ctx structure instead of a
    completely opaque token.  Relying on producers and consumers to set the
    token appropriately is error prone, and hiding the fact that the token must
    be an eventfd_ctx pointer (for all intents and purposes) unnecessarily
    obfuscates the code and makes it more brittle.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-4-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson b2de8b8c59 irqbypass: Drop superfluous might_sleep() annotations
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 07fbc83c01520c62c89f6495f2f0bea2f4ac6684
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:28 2025 -0700

    irqbypass: Drop superfluous might_sleep() annotations

    Drop superfluous might_sleep() annotations from irqbypass, mutex_lock()
    provides all of the necessary tracking.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-3-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson b7582671c4 irqbypass: Drop pointless and misleading THIS_MODULE get/put
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit fa079a0616edbcdad538128306abbc19b68a9863
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri May 16 16:07:27 2025 -0700

    irqbypass: Drop pointless and misleading THIS_MODULE get/put

    Drop irqbypass.ko's superfluous and misleading get/put calls on
    THIS_MODULE.  A module taking a reference to itself is useless; no amount
    of checks will prevent doom and destruction if the caller hasn't already
    guaranteed the liveliness of the module (this goes for any module).  E.g.
    if try_module_get() fails because irqbypass.ko is being unloaded, then the
    kernel has already hit a use-after-free by virtue of executing code whose
    lifecycle is tied to irqbypass.ko.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
    Link: https://lore.kernel.org/r/20250516230734.2564775-2-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 16fb1bfea5 vfio/type1: Fix error unwind in migration dirty bitmap allocation
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 4518e5a60c7fbf0cdff393c2681db39d77b4f87e
Author: Li RongQing <lirongqing@baidu.com>
Date:   Wed May 21 11:46:47 2025 +0800

    vfio/type1: Fix error unwind in migration dirty bitmap allocation

    When setting up dirty page tracking at the vfio IOMMU backend for
    device migration, if an error is encountered allocating a tracking
    bitmap, the unwind loop fails to free previously allocated tracking
    bitmaps.  This occurs because the wrong loop index is used to
    generate the tracking object.  This results in unintended memory
    usage for the life of the current DMA mappings where bitmaps were
    successfully allocated.

    Use the correct loop index to derive the tracking object for
    freeing during unwind.

    Fixes: d6a4c18566 ("vfio iommu: Implementation of ioctl for dirty pages tracking")
    Signed-off-by: Li RongQing <lirongqing@baidu.com>
    Link: https://lore.kernel.org/r/20250521034647.2877-1-lirongqing@baidu.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 90f6188718 vfio/mlx5: Enable the DMA link API
JIRA: https://issues.redhat.com/browse/RHEL-118213
Conflicts: 6bf9b5b40af3 ("mm: alloc_pages_bulk: rename API") is not
           yet backported, continue to use alloc_pages_bulk_array().

commit 089803c40193ccce21da04d9f047468eba3aa47f
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue May 20 16:46:32 2025 +0300

    vfio/mlx5: Enable the DMA link API

    Remove intermediate scatter-gather table completely and
    enable new DMA link API.

    Tested-by: Jens Axboe <axboe@kernel.dk>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Acked-by: Yishai Hadas <yishaih@nvidia.com>
    Link: https://lore.kernel.org/r/f71638d50c9c79a462f2e0423501b1de77617656.1747747694.git.leon@kernel.org
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:36:58 -06:00
Alex Williamson 576485c7ec vfio/mlx5: Rewrite create mkey flow to allow better code reuse
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit ac6c973a480bcbd1161974b6b8ec6fd12e87b506
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue May 20 16:46:31 2025 +0300

    vfio/mlx5: Rewrite create mkey flow to allow better code reuse

    Change the creation of mkey to be performed in multiple steps:
    data allocation, DMA setup and actual call to HW to create that mkey.

    In this new flow, the whole input to MKEY command is saved to eliminate
    the need to keep array of pointers for DMA addresses for receive list
    and in the future patches for send list too.

    In addition to memory size reduce and elimination of unnecessary data
    movements to set MKEY input, the code is prepared for future reuse.

    Tested-by: Jens Axboe <axboe@kernel.dk>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Acked-by: Yishai Hadas <yishaih@nvidia.com>
    Link: https://lore.kernel.org/r/d4ad0384fbd1e23a607cbbe9e5756748f3a761d9.1747747694.git.leon@kernel.org
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:58 -06:00
Alex Williamson 9b919edcfe vfio/mlx5: Explicitly use number of pages instead of allocated length
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 674ebb64cd5dc40827b8ac8c95bb72d328ed59ff
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue May 20 16:46:30 2025 +0300

    vfio/mlx5: Explicitly use number of pages instead of allocated length

    allocated_length is a multiple of page size and number of pages,
    so let's change the functions to accept number of pages. This improves
    code readability, simplifies buffer handling, and enables combining DMA
    send/receive operations, as will be introduced in the next patches.

    Tested-by: Jens Axboe <axboe@kernel.dk>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Acked-by: Yishai Hadas <yishaih@nvidia.com>
    Link: https://lore.kernel.org/r/76f39993d2ca0311b3bcfe56038a669d03926815.1747747694.git.leon@kernel.org
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:58 -06:00
Alex Williamson 965f8ab195 hisi_acc_vfio_pci: update function return values.
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 1dcf2cf102d72e0bbf0d7533756c9a0ccb6e91d3
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:55 2025 +0800

    hisi_acc_vfio_pci: update function return values.

    In this driver file, many functions call sub-functions and use ret
    to store the error code of the sub-functions.
    However, instead of directly returning ret to the caller, they use a
    converted error code, which prevents the end-user from clearly
    understanding the root cause of the error.
    Therefore, the code needs to be modified to directly return the error
    code from the sub-functions.

    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-7-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:58 -06:00
Alex Williamson 30a0359234 hisi_acc_vfio_pci: bugfix live migration function without VF device driver
JIRA: https://issues.redhat.com/browse/RHEL-118213
CVE: CVE-2025-38283

commit 2777a40998deb36f96b6afc48bd397cf58a4edf0
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:54 2025 +0800

    hisi_acc_vfio_pci: bugfix live migration function without VF device driver

    If the VF device driver is not loaded in the Guest OS and we attempt to
    perform device data migration, the address of the migrated data will
    be NULL.
    The live migration recovery operation on the destination side will
    access a null address value, which will cause access errors.

    Therefore, live migration of VMs without added VF device drivers
    does not require device data migration.
    In addition, when the queue address data obtained by the destination
    is empty, device queue recovery processing will not be performed.

    Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-6-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:58 -06:00
Alex Williamson c4a92d61c3 hisi_acc_vfio_pci: bugfix the problem of uninstalling driver
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit db6525a8573957faea28850392f4744e5f8f7a53
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:53 2025 +0800

    hisi_acc_vfio_pci: bugfix the problem of uninstalling driver

    In a live migration scenario. If the number of VFs at the
    destination is greater than the source, the recovery operation
    will fail and qemu will not be able to complete the process and
    exit after shutting down the device FD.

    This will cause the driver to be unable to be unloaded normally due
    to abnormal reference counting of the live migration driver caused
    by the abnormal closing operation of fd.

    Therefore, make sure the migration file descriptor references are
    always released when the device is closed.

    Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-5-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:35 -06:00
Alex Williamson 1210b23c6d hisi_acc_vfio_pci: bugfix cache write-back issue
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit e63c466398731bb7867f42f44b76fa984de59db2
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:52 2025 +0800

    hisi_acc_vfio_pci: bugfix cache write-back issue

    At present, cache write-back is placed in the device data
    copy stage after stopping the device operation.
    Writing back to the cache at this stage will cause the data
    obtained by the cache to be written back to be empty.

    In order to ensure that the cache data is written back
    successfully, the data needs to be written back into the
    stop device stage.

    Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-4-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:35 -06:00
Alex Williamson 03f9d87ea6 hisi_acc_vfio_pci: add eq and aeq interruption restore
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 3495cec0787721ba7a9d5c19d0bbb66d182de584
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:51 2025 +0800

    hisi_acc_vfio_pci: add eq and aeq interruption restore

    In order to ensure that the task packets of the accelerator
    device are not lost during the migration process, it is necessary
    to send an EQ and AEQ command to the device after the live migration
    is completed and to update the completion position of the task queue.

    Let the device recheck the completed tasks data and if there are
    uncollected packets, device resend a task completion interrupt
    to the software.

    Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-3-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:35 -06:00
Alex Williamson ee18637905 hisi_acc_vfio_pci: fix XQE dma address error
JIRA: https://issues.redhat.com/browse/RHEL-118213
CVE: CVE-2025-38158

commit 8bb7170c5a055ea17c6857c256ee73c10ff872eb
Author: Longfang Liu <liulongfang@huawei.com>
Date:   Sat May 10 16:11:50 2025 +0800

    hisi_acc_vfio_pci: fix XQE dma address error

    The dma addresses of EQE and AEQE are wrong after migration and
    results in guest kernel-mode encryption services  failure.
    Comparing the definition of hardware registers, we found that
    there was an error when the data read from the register was
    combined into an address. Therefore, the address combination
    sequence needs to be corrected.

    Even after fixing the above problem, we still have an issue
    where the Guest from an old kernel can get migrated to
    new kernel and may result in wrong data.

    In order to ensure that the address is correct after migration,
    if an old magic number is detected, the dma address needs to be
    updated.

    Fixes: b0eed08590 ("hisi_acc_vfio_pci: Add support for VFIO live migration")
    Signed-off-by: Longfang Liu <liulongfang@huawei.com>
    Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Link: https://lore.kernel.org/r/20250510081155.55840-2-liulongfang@huawei.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-09 12:35:35 -06:00
Alex Williamson 9c36941658 vfio/type1: Remove Fine Grained Superpages detection
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 07970d048cddeb56fa17925d7c37cb2400322aab
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date:   Mon Apr 14 10:46:39 2025 -0300

    vfio/type1: Remove Fine Grained Superpages detection

    VFIO is looking to enable an optimization where it can rely on a fast
    unmap operation that returned the size of a larger IOPTE.

    Due to how the test was constructed this would only ever succeed on the
    AMDv1 page table that supported an 8k contiguous size. Nothing else
    supports this.

    Alex says the performance win was fairly minor, so lets remove this
    code. Always use iommu_iova_to_phys() to extent contiguous pages.

    Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
    Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Link: https://lore.kernel.org/r/0-v2-97fa1da8d983+412-vfio_fgsp_jgg@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-07 15:27:19 -06:00
Alex Williamson b09c5f107b vfio/pci: Virtualize zero INTx PIN if no pdev->irq
JIRA: https://issues.redhat.com/browse/RHEL-118213

commit 2bd42b03ab6b04dde1753bd6b38eeca5c70f3941
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Thu Mar 20 13:41:42 2025 -0600

    vfio/pci: Virtualize zero INTx PIN if no pdev->irq

    Typically pdev->irq is consistent with whether the device itself
    supports INTx, where device support is reported via the PIN register.
    Therefore the PIN register is often already zero if pdev->irq is zero.

    Recently virtualization of the PIN register was expanded to include
    the case where the device supports INTx but the platform does not
    route the interrupt.  This is reported by a value of IRQ_NOTCONNECTED
    on some architectures.  Other architectures just report zero for
    pdev->irq.

    We already disallow INTx setup if pdev->irq is zero, therefore add
    this to the PIN register virtualization criteria so that a consistent
    view is provided to userspace through virtualized config space and
    ioctls.

    Reported-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
    Link: https://lore.kernel.org/all/174231895238.2295.12586708771396482526.stgit@linux.ibm.com/
    Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
    Link: https://lore.kernel.org/r/20250320194145.2816379-1-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-10-07 15:26:29 -06:00
Alex Williamson ce4218f62e vfio/pci: Align huge faults to order
JIRA: https://issues.redhat.com/browse/RHEL-89852

commit c1d9dac0db168198b6f63f460665256dedad9b6e
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri May 2 16:40:31 2025 -0600

    vfio/pci: Align huge faults to order

    The vfio-pci huge_fault handler doesn't make any attempt to insert a
    mapping containing the faulting address, it only inserts mappings if the
    faulting address and resulting pfn are aligned.  This works in a lot of
    cases, particularly in conjunction with QEMU where DMA mappings linearly
    fault the mmap.  However, there are configurations where we don't get
    that linear faulting and pages are faulted on-demand.

    The scenario reported in the bug below is such a case, where the physical
    address width of the CPU is greater than that of the IOMMU, resulting in a
    VM where guest firmware has mapped device MMIO beyond the address width of
    the IOMMU.  In this configuration, the MMIO is faulted on demand and
    tracing indicates that occasionally the faults generate a VM_FAULT_OOM.
    Given the use case, this results in a "error: kvm run failed Bad address",
    killing the VM.

    The host is not under memory pressure in this test, therefore it's
    suspected that VM_FAULT_OOM is actually the result of a NULL return from
    __pte_offset_map_lock() in the get_locked_pte() path from insert_pfn().
    This suggests a potential race inserting a pte concurrent to a pmd, and
    maybe indicates some deficiency in the mm layer properly handling such a
    case.

    Nevertheless, Peter noted the inconsistency of vfio-pci's huge_fault
    handler where our mapping granularity depends on the alignment of the
    faulting address relative to the order rather than aligning the faulting
    address to the order to more consistently insert huge mappings.  This
    change not only uses the page tables more consistently and efficiently, but
    as any fault to an aligned page results in the same mapping, the race
    condition suspected in the VM_FAULT_OOM is avoided.

    Reported-by: Adolfo <adolfotregosa@gmail.com>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220057
    Fixes: 09dfc8a5f2ce ("vfio/pci: Fallback huge faults for unaligned pfn")
    Cc: stable@vger.kernel.org
    Tested-by: Adolfo <adolfotregosa@gmail.com>
    Co-developed-by: Peter Xu <peterx@redhat.com>
    Signed-off-by: Peter Xu <peterx@redhat.com>
    Link: https://lore.kernel.org/r/20250502224035.3183451-1-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-05-08 13:29:14 -06:00
Alex Williamson 3c93e95436 vfio/pci: Handle INTx IRQ_NOTCONNECTED
JIRA: https://issues.redhat.com/browse/RHEL-85587
JIRA: https://issues.redhat.com/browse/RHEL-85591

commit 860be250fc32de9cb24154bf21b4e36f40925707
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Mar 11 17:06:21 2025 -0600

    vfio/pci: Handle INTx IRQ_NOTCONNECTED

    Some systems report INTx as not routed by setting pdev->irq to
    IRQ_NOTCONNECTED, resulting in a -ENOTCONN error when trying to
    setup eventfd signaling.  Include this in the set of conditions
    for which the PIN register is virtualized to zero.

    Additionally consolidate vfio_pci_get_irq_count() to use this
    virtualized value in reporting INTx support via ioctl and sanity
    checking ioctl paths since pdev->irq is re-used when the device
    is in MSI mode.

    The combination of these results in both the config space of the
    device and the ioctl interface behaving as if the device does not
    support INTx.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Link: https://lore.kernel.org/r/20250311230623.1264283-1-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 15:04:24 -06:00
Alex Williamson d9a58c4ad5 vfio/virtio: Enable support for virtio-block live migration
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 384a530111c682d4a6c4c9ec305254c323a1379a
Author: Yishai Hadas <yishaih@nvidia.com>
Date:   Sun Mar 2 18:27:23 2025 +0200

    vfio/virtio: Enable support for virtio-block live migration

    With a functional and tested backend for virtio-block live migration,
    add the virtio-block device ID to the pci_device_id table.

    Currently, the driver supports legacy IO functionality only for
    virtio-net, and it is accounted for in specific parts of the code.

    To enforce this limitation, an explicit check for virtio-net, has been
    added in virtiovf_support_legacy_io(). Once a backend implements legacy
    IO functionality for virtio-block, the necessary support will be added
    to the driver, and this additional check should be removed.

    The module description was updated accordingly.

    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
    Link: https://lore.kernel.org/r/20250302162723.82578-1-yishaih@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:53 -06:00
Alex Williamson d983f15bc2 vfio/type1: Use mapping page mask for pfnmaps
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 0fd06844de5d063cb384384e06a11ec7141a35d5
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:06 2025 -0700

    vfio/type1: Use mapping page mask for pfnmaps

    vfio-pci supports huge_fault for PCI MMIO BARs and will insert pud and
    pmd mappings for well aligned mappings.  follow_pfnmap_start() walks the
    page table and therefore knows the page mask of the level where the
    address is found and returns this through follow_pfnmap_args.addr_mask.
    Subsequent pfns from this address until the end of the mapping page are
    necessarily consecutive.  Use this information to retrieve a range of
    pfnmap pfns in a single pass.

    With optimal mappings and alignment on systems with 1GB pud and 4KB
    page size, this reduces iterations for DMA mapping PCI BARs by a
    factor of 256K.  In real world testing, the overhead of iterating
    pfns for a VM DMA mapping a 32GB PCI BAR is reduced from ~1s to
    sub-millisecond overhead.

    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-7-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:53 -06:00
Alex Williamson 28ec4292fe mm: Provide address mask in struct follow_pfnmap_args
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 62fb8adc43afad5fa1c9cadc6f3a8e9fb72af194
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:05 2025 -0700

    mm: Provide address mask in struct follow_pfnmap_args

    follow_pfnmap_start() walks the page table for a given address and
    fills out the struct follow_pfnmap_args in pfnmap_args_setup().
    The address mask of the page table level is already provided to this
    latter function for calculating the pfn.  This address mask can also
    be useful for the caller to determine the extent of the contiguous
    mapping.

    For example, vfio-pci now supports huge_fault for pfnmaps and is able
    to insert pud and pmd mappings.  When we DMA map these pfnmaps, ex.
    PCI MMIO BARs, we iterate follow_pfnmap_start() to get each pfn to test
    for a contiguous pfn range.  Providing the mapping address mask allows
    us to skip the extent of the mapping level.  Assuming a 1GB pud level
    and 4KB page size, iterations are reduced by a factor of 256K.  In wall
    clock time, mapping a 32GB PCI BAR is reduced from ~1s to <1ms.

    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: linux-mm@kvack.org
    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Acked-by: David Hildenbrand <david@redhat.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-6-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:53 -06:00
Alex Williamson 3560c0d0d0 vfio/type1: Use consistent types for page counts
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 0635559233434a337aa1c20d53abae18b3663796
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:04 2025 -0700

    vfio/type1: Use consistent types for page counts

    Page count should more consistently be an unsigned long when passed as
    an argument while functions returning a number of pages should use a
    signed long to allow for -errno.

    vaddr_get_pfns() can therefore be upgraded to return long, though in
    practice it's currently limited by the batch capacity.  In fact, the
    batch indexes are noted to never hold negative values, so while it
    doesn't make sense to bloat the structure with unsigned longs in this
    case, it does make sense to specify these as unsigned.

    No change in behavior expected.

    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-5-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson 860cd61420 vfio/type1: Use vfio_batch for vaddr_get_pfns()
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit eb996eec783c1e7e1e9c62e0336f8b86a08cf541
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:03 2025 -0700

    vfio/type1: Use vfio_batch for vaddr_get_pfns()

    Passing the vfio_batch to vaddr_get_pfns() allows for greater
    distinction between page backed pfns and pfnmaps.  In the case of page
    backed pfns, vfio_batch.size is set to a positive value matching the
    number of pages filled in vfio_batch.pages.  For a pfnmap,
    vfio_batch.size remains zero as vfio_batch.pages are not used.  In both
    cases the return value continues to indicate the number of pfns and the
    provided pfn arg is set to the initial pfn value.

    This allows us to shortcut the pfnmap case, which is detected by the
    zero vfio_batch.size.  pfnmaps do not contribute to locked memory
    accounting, therefore we can update counters and continue directly,
    which also enables a future where vaddr_get_pfns() can return a value
    greater than one for consecutive pfnmaps.

    NB. Now that we're not guessing whether the initial pfn is page backed
    or pfnmap, we no longer need to special case the put_pfn() and batch
    size reset.  It's safe for vfio_batch_unpin() to handle this case.

    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-4-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson e8ccfb8c9a vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 7a701e90fc8e3d7a7d07246b14c59a2da258539a
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:02 2025 -0700

    vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch

    This is a step towards passing the structure to vaddr_get_pfns()
    directly in order to provide greater distinction between page backed
    pfns and pfnmaps.

    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-3-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson 4eb4e96b0b vfio/type1: Catch zero from pin_user_pages_remote()
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit afe84f3b7a26037b258be0f0a1e1754fc1db37e8
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Tue Feb 18 15:22:01 2025 -0700

    vfio/type1: Catch zero from pin_user_pages_remote()

    pin_user_pages_remote() can currently return zero for invalid args
    or zero nr_pages, neither of which should ever happen.  However
    vaddr_get_pfns() indicates it should only ever return a positive
    value or -errno and there's a theoretical case where this can slip
    through and be unhandled by callers.  Therefore convert zero to
    -EFAULT.

    Reviewed-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20250218222209.1382449-2-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson fc40056b31 vfio/pci: match IGD devices in display controller class
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 41112160ca87d6b5280813ef61f1c35bb9ee2f82
Author: Tomita Moeko <tomitamoeko@gmail.com>
Date:   Fri Jan 24 00:34:15 2025 +0800

    vfio/pci: match IGD devices in display controller class

    IGD device can either expose as a VGA controller or display controller
    depending on whether it is configured as the primary display device in
    BIOS. In both cases, the OpRegion may be present. A new helper function
    vfio_pci_is_intel_display() is introduced to check if the device might
    be an IGD device.

    Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
    Link: https://lore.kernel.org/r/20250123163416.7653-1-tomitamoeko@gmail.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson ab37406654 vfio/nvgrace-gpu: Add GB200 SKU to the devid table
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 2bb447540e71ee530388750c38e1b2c8ea08b4b7
Author: Ankit Agrawal <ankita@nvidia.com>
Date:   Fri Jan 24 18:31:02 2025 +0000

    vfio/nvgrace-gpu: Add GB200 SKU to the devid table

    NVIDIA is productizing the new Grace Blackwell superchip
    SKU bearing device ID 0x2941.

    Add the SKU devid to nvgrace_gpu_vfio_pci_table.

    CC: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/20250124183102.3976-5-ankita@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson 00150e4c86 vfio/nvgrace-gpu: Check the HBM training and C2C link status
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit d85f69d520e6aca8ae5ce353666e2fc2756eb9e7
Author: Ankit Agrawal <ankita@nvidia.com>
Date:   Fri Jan 24 18:31:01 2025 +0000

    vfio/nvgrace-gpu: Check the HBM training and C2C link status

    In contrast to Grace Hopper systems, the HBM training has been moved
    out of the UEFI on the Grace Blackwell systems. This reduces the system
    bootup time significantly.

    The onus of checking whether the HBM training has completed thus falls
    on the module.

    The HBM training status can be determined from a BAR0 register.
    Similarly, another BAR0 register exposes the status of the CPU-GPU
    chip-to-chip (C2C) cache coherent interconnect.

    Based on testing, 30s is determined to be sufficient to ensure
    initialization completion on all the Grace based systems. Thus poll
    these register and check for 30s. If the HBM training is not complete
    or if the C2C link is not ready, fail the probe.

    While the time is not required on Grace Hopper systems, it is
    beneficial to make the check to ensure the device is in an
    expected state. Hence keeping it generalized to both the generations.

    Ensure that the BAR0 is enabled before accessing the registers.

    CC: Alex Williamson <alex.williamson@redhat.com>
    CC: Kevin Tian <kevin.tian@intel.com>
    CC: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/20250124183102.3976-4-ankita@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson 7f99e77b90 vfio/nvgrace-gpu: Expose the blackwell device PF BAR1 to the VM
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 6a9eb2d125ba90d13b45bcfabcddf9f61268f6a8
Author: Ankit Agrawal <ankita@nvidia.com>
Date:   Fri Jan 24 18:31:00 2025 +0000

    vfio/nvgrace-gpu: Expose the blackwell device PF BAR1 to the VM

    There is a HW defect on Grace Hopper (GH) to support the
    Multi-Instance GPU (MIG) feature [1] that necessiated the presence
    of a 1G region carved out from the device memory and mapped as
    uncached. The 1G region is shown as a fake BAR (comprising region 2 and 3)
    to workaround the issue.

    The Grace Blackwell systems (GB) differ from GH systems in the following
    aspects:
    1. The aforementioned HW defect is fixed on GB systems.
    2. There is a usable BAR1 (region 2 and 3) on GB systems for the
    GPUdirect RDMA feature [2].

    This patch accommodate those GB changes by showing the 64b physical
    device BAR1 (region2 and 3) to the VM instead of the fake one. This
    takes care of both the differences.

    Moreover, the entire device memory is exposed on GB as cacheable to
    the VM as there is no carveout required.

    Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [1]
    Link: https://docs.nvidia.com/cuda/gpudirect-rdma/ [2]

    Cc: Kevin Tian <kevin.tian@intel.com>
    CC: Jason Gunthorpe <jgg@nvidia.com>
    Suggested-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/20250124183102.3976-3-ankita@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:52 -06:00
Alex Williamson 51323e00de vfio/nvgrace-gpu: Read dvsec register to determine need for uncached resmem
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit bd53764a60ad586ad5b6ed339423ad5e67824464
Author: Ankit Agrawal <ankita@nvidia.com>
Date:   Fri Jan 24 18:30:59 2025 +0000

    vfio/nvgrace-gpu: Read dvsec register to determine need for uncached resmem

    NVIDIA's recently introduced Grace Blackwell (GB) Superchip is a
    continuation with the Grace Hopper (GH) superchip that provides a
    cache coherent access to CPU and GPU to each other's memory with
    an internal proprietary chip-to-chip cache coherent interconnect.

    There is a HW defect on GH systems to support the Multi-Instance
    GPU (MIG) feature [1] that necessiated the presence of a 1G region
    with uncached mapping carved out from the device memory. The 1G
    region is shown as a fake BAR (comprising region 2 and 3) to
    workaround the issue. This is fixed on the GB systems.

    The presence of the fix for the HW defect is communicated by the
    device firmware through the DVSEC PCI config register with ID 3.
    The module reads this to take a different codepath on GB vs GH.

    Scan through the DVSEC registers to identify the correct one and use
    it to determine the presence of the fix. Save the value in the device's
    nvgrace_gpu_pci_core_device structure.

    Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [1]

    CC: Jason Gunthorpe <jgg@nvidia.com>
    CC: Kevin Tian <kevin.tian@intel.com>
    Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
    Link: https://lore.kernel.org/r/20250124183102.3976-2-ankita@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00
Alex Williamson b2ab73c5f9 vfio/platform: check the bounds of read/write syscalls
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit ce9ff21ea89d191e477a02ad7eabf4f996b80a69
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Wed Jan 22 10:38:30 2025 -0700

    vfio/platform: check the bounds of read/write syscalls

    count and offset are passed from user space and not checked, only
    offset is capped to 40 bits, which can be used to read/write out of
    bounds of the device.

    Fixes: 6e3f264560 (“vfio/platform: read and write support for the device fd”)
    Cc: stable@vger.kernel.org
    Reported-by: Mostafa Saleh <smostafa@google.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Reviewed-by: Mostafa Saleh <smostafa@google.com>
    Tested-by: Mostafa Saleh <smostafa@google.com>
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00
Alex Williamson 8585b1c1b2 vfio/pci: Expose setup ROM at ROM bar when needed
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit e021e6cbfb5a695968afb6619828929a97e4a83a
Author: Yunxiang Li <Yunxiang.Li@amd.com>
Date:   Thu Jan 2 13:50:13 2025 -0500

    vfio/pci: Expose setup ROM at ROM bar when needed

    If ROM bar is missing for any reason, we can fallback to using pdev->rom
    to expose the ROM content to the guest. This fixes some passthrough use
    cases where the upstream bridge does not have enough address window.

    Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
    Link: https://lore.kernel.org/r/20250102185013.15082-3-Yunxiang.Li@amd.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00
Alex Williamson 53d5320514 vfio/pci: Remove shadow ROM specific code paths
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit c5a8b5d740ef3dde319562d2e969888b4b8dfdd8
Author: Yunxiang Li <Yunxiang.Li@amd.com>
Date:   Thu Jan 2 13:50:12 2025 -0500

    vfio/pci: Remove shadow ROM specific code paths

    After commit 0c0e0736ac ("PCI: Set ROM shadow location in arch code,
    not in PCI core"), the shadow ROM works the same as regular ROM BARs so
    these code paths are no longer needed.

    Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
    Link: https://lore.kernel.org/r/20250102185013.15082-2-Yunxiang.Li@amd.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00
Alex Williamson 966e94e507 vfio/pci: Remove #ifdef iowrite64 and #ifdef ioread64
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit b44a06bd28f2732393c2019e3ae0e593ef76c867
Author: Ramesh Thomas <ramesh.thomas@intel.com>
Date:   Tue Dec 10 05:19:38 2024 -0800

    vfio/pci: Remove #ifdef iowrite64 and #ifdef ioread64

    Remove the #ifdef iowrite64 and #ifdef ioread64 checks around calls to
    64 bit IO access. Since default implementations have been enabled, the
    checks are not required.

    Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20241210131938.303500-3-ramesh.thomas@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00
Alex Williamson bc73e9f5ee vfio/pci: Enable iowrite64 and ioread64 for vfio pci
JIRA: https://issues.redhat.com/browse/RHEL-85587

commit 2b938e3db335e3670475e31a722c2bee34748c5a
Author: Ramesh Thomas <ramesh.thomas@intel.com>
Date:   Tue Dec 10 05:19:37 2024 -0800

    vfio/pci: Enable iowrite64 and ioread64 for vfio pci

    Definitions of ioread64 and iowrite64 macros in asm/io.h called by vfio
    pci implementations are enclosed inside check for CONFIG_GENERIC_IOMAP.
    They don't get defined if CONFIG_GENERIC_IOMAP is defined. Include
    linux/io-64-nonatomic-lo-hi.h to define iowrite64 and ioread64 macros
    when they are not defined. io-64-nonatomic-lo-hi.h maps the macros to
    generic implementation in lib/iomap.c. The generic implementation does
    64 bit rw if readq/writeq is defined for the architecture, otherwise it
    would do 32 bit back to back rw.

    Note that there are two versions of the generic implementation that
    differs in the order the 32 bit words are written if 64 bit support is
    not present. This is not the little/big endian ordering, which is
    handled separately. This patch uses the lo followed by hi word ordering
    which is consistent with current back to back implementation in the
    vfio/pci code.

    Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20241210131938.303500-2-ramesh.thomas@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2025-03-31 14:06:51 -06:00