[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Backport bugfixes for QuickAssist Technology(QAT) live migration for in-tree driver#859
Conversation
[ Upstream commit 2780025 ] IOVA bitmap is a zero-copy scheme of recording dirty bits that iterate the different bitmap user pages at chunks of a maximum of PAGE_SIZE/sizeof(struct page*) pages. When the iterations are split up into 64G, the end of the range may be broken up in a way that's aligned with a non base page PTE size. This leads to only part of the huge page being recorded in the bitmap. Note that in pratice this is only a problem for IOMMU dirty tracking i.e. when the backing PTEs are in IOMMU hugepages and the bitmap is in base page granularity. So far this not something that affects VF dirty trackers (which reports and records at the same granularity). To fix that, if there is a remainder of bits left to set in which the current IOVA bitmap doesn't cover, make a copy of the bitmap structure and iterate-and-set the rest of the bits remaining. Finally, when advancing the iterator, skip all the bits that were set ahead. Link: https://lore.kernel.org/r/20240202133415.23819-5-joao.m.martins@oracle.com Reported-by: Avihai Horon <avihaih@nvidia.com> Fixes: f35f22c ("iommu/vt-d: Access/Dirty bit support for SS domains") Fixes: 421a511 ("iommu/amd: Access/Dirty bit support in IOPTEs") Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Tested-by: Avihai Horon <avihaih@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.9 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit cf1e515 ] The sparse tool complains as follows: drivers/iommu/iommufd/selftest.c:277:30: warning: symbol 'dirty_ops' was not declared. Should it be static? This symbol is not used outside of selftest.c, so marks it static. Fixes: 266ce58 ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING") Link: https://patch.msgid.link/r/20240819120007.3884868-1-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.12 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 8541323 ] Some kconfigs don't automatically include this symbol which results in sub functions for some of the dirty tracking related things that are non-functional. Thus the test suite will fail. select IOMMUFD_DRIVER in the IOMMUFD_TEST kconfig to fix it. Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Link: https://lore.kernel.org/r/20240327182050.GA1363414@ziepe.ca Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.9 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 2760c51 ] Add FAULT_INJECTION_DEBUG_FS and FAILSLAB configurations to the kconfig fragment for the iommfd selftests. These kconfigs are needed by the iommufd_fail_nth test. Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Link: https://lore.kernel.org/r/20240325090048.1423908-1-usama.anjum@collabora.com Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.9-rc4 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit ec61f82 ] With 64k base pages, the first 128k iova length test requires less than a byte for a bitmap, exposing a bug in the tests that assume that bitmaps are at least a byte. Rather than dealing with bytes, have _test_mock_dirty_bitmaps() pass the number of bits. The caller functions are adjusted to also use bits as well, and converting to bytes when clearing, allocating and freeing the bitmap. Link: https://lore.kernel.org/r/20240627110105.62325-2-joao.m.martins@oracle.com Reported-by: Matt Ochs <mochs@nvidia.com> Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Matt Ochs <mochs@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.10 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 9560393 ] The calculation returns 0 if it sets less than the number of bits per byte. For calculating memory allocation from bits, lets round it up to one byte. Link: https://lore.kernel.org/r/20240627110105.62325-3-joao.m.martins@oracle.com Reported-by: Matt Ochs <mochs@nvidia.com> Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Matt Ochs <mochs@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.10 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit ffa3c79 ] commit a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") added tests covering edge cases in the boundaries of iova bitmap. Although it used buffer sizes thinking in PAGE_SIZE (4K) as opposed to the MOCK_PAGE_SIZE (2K) that is used in iommufd mock selftests. This meant that isn't correctly exercising everything specifically the u32 and 4K bitmap test cases. Fix selftests buffer sizes to be based on mock page size. Link: https://lore.kernel.org/r/20240627110105.62325-5-joao.m.martins@oracle.com Reported-by: Kevin Tian <kevin.tian@intel.com> Closes: https://lore.kernel.org/linux-iommu/96efb6cf-a41c-420f-9673-2f0b682cac8c@oracle.com/ Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Matt Ochs <mochs@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> [ Backport from v6.10 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 694a6f5 ] The macro `ADF_RP_INT_SRC_SEL_F_RISE_MASK` is currently set to the value `0100b` which means "Empty Going False". This might cause an incorrect restore of the bank state during live migration. Fix the definition of the macro to properly represent the "Full Going True" state which is encoded as `0011b`. Fixes: bbfdde7 ("crypto: qat - add bank save and restore flows") Signed-off-by: Svyatoslav Pankratov <svyatoslav.pankratov@intel.com> Reviewed-by: Xin Zeng <xin.zeng@intel.com> Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> [ Backport from v6.11-rc5 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit a5d8922 ] When CONFIG_PCI_IOV=n, the build of the QAT vfio pci variant driver fails reporting the following linking errors: ERROR: modpost: "qat_vfmig_open" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_resume" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_save_state" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_suspend" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_load_state" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_reset" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_save_setup" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_destroy" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_close" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! ERROR: modpost: "qat_vfmig_cleanup" [drivers/vfio/pci/qat/qat_vfio_pci.ko] undefined! WARNING: modpost: suppressed 1 unresolved symbol warnings because there were too many) Make live migration helpers provided by QAT PF driver always available even if CONFIG_PCI_IOV is not selected. This does not cause any side effect. Reported-by: Arnd Bergmann <arnd@arndb.de> Closes: https://lore.kernel.org/lkml/20240607153406.60355e6c.alex.williamson@redhat.com/T/ Fixes: bb20881 ("vfio/qat: Add vfio_pci driver for Intel QAT SR-IOV VF devices") Signed-off-by: Xin Zeng <xin.zeng@intel.com> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> [ Backport from v6.11 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 9283b73 ] The unsigned variable `size_t len` is cast to the signed type `loff_t` when passed to the function check_add_overflow(). This function considers the type of the destination, which is of type loff_t (signed), potentially leading to an overflow. This issue is similar to the one described in the link below. Remove the cast. Note that even if check_add_overflow() is bypassed, by setting `len` to a value that is greater than LONG_MAX (which is considered as a negative value after the cast), the function copy_from_user(), invoked a few lines later, will not perform any copy and return `len` as (len > INT_MAX) causing qat_vf_resume_write() to fail with -EFAULT. Fixes: bb20881 ("vfio/qat: Add vfio_pci driver for Intel QAT SR-IOV VF devices") CC: stable@vger.kernel.org # 6.10+ Link: https://lore.kernel.org/all/138bd2e2-ede8-4bcc-aa7b-f3d9de167a37@moroto.mountain Reported-by: Zijie Zhao <zzjas98@gmail.com> Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Xin Zeng <xin.zeng@intel.com> Link: https://lore.kernel.org/r/20241021123843.42979-1-giovanni.cabiddu@intel.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> [ Backport from v6.12 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
Reviewer's GuideThis PR backports upstream QAT live migration fixes by integrating the migration device into the QAT build and correcting mask and overflow checks, extends the IOVA bitmap with a “set ahead” mechanism for pre-pinning, and refactors selftests to unify bitmap size calculations using DIV_ROUND_UP (including marking dirty_ops static) Sequence Diagram for IOVA Bitmap Set-Ahead LogicsequenceDiagram
participant Caller
participant iova_bitmap_set() as IBS
participant iova_bitmap_advance() as IBA
participant iova_bitmap_set_ahead() as IBSA
participant iova_bitmap_struct as "iova_bitmap instance"
Caller->>IBS: Call iova_bitmap_set(bitmap, iova, length)
IBS->>iova_bitmap_struct: Update bitmap->set_ahead_length (if conditions met)
IBS-->>Caller: Return
%% Later in execution flow, or in a different context
Caller->>IBA: Call iova_bitmap_advance(bitmap)
IBA->>iova_bitmap_struct: Read bitmap->set_ahead_length
alt If bitmap->set_ahead_length > 0
IBA->>IBSA: Call iova_bitmap_set_ahead(bitmap, bitmap->set_ahead_length)
IBSA->>iova_bitmap_struct: Loop (get pages, set bits in bitmap, put pages)
IBSA->>iova_bitmap_struct: bitmap->set_ahead_length = 0
IBSA-->>IBA: Return (status)
end
IBA-->>Caller: Return (status)
Updated Class Diagram for iova_bitmap StructureclassDiagram
class iova_bitmap {
+unsigned long set_ahead_length
+iova_bitmap_set_ahead(size_t set_ahead_length) : int
+iova_bitmap_advance() : int
+iova_bitmap_set(unsigned long iova, unsigned long length) : void
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull Request Overview
This PR backports bugfixes for QuickAssist Technology (QAT) live migration and includes related adjustments to IOMMU test utilities and configurations.
- Fixes in dirty bitmap size calculations and memory allocation in IOMMU selftests
- Updates to IOMMU and QAT driver configurations and object files
- Adjustments to interrupt mask definitions for QAT hardware
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/testing/selftests/iommu/iommufd_utils.h | Introduces DIV_ROUND_UP macro and updates dirty bitmap calculations |
| tools/testing/selftests/iommu/iommufd.c | Corrects bitmap size calculation and updates fixture variants for testing |
| tools/testing/selftests/iommu/config | Adds additional configuration options for fault injection and debugging |
| drivers/vfio/pci/qat/main.c | Modifies check_add_overflow call to use the correct length parameter |
| drivers/iommu/iommufd/selftest.c | Adjusts bitmap size calculation using DIV_ROUND_UP for clarity |
| drivers/iommu/iommufd/iova_bitmap.c | Adds a mechanism (set_ahead) for handling unmapped bitmap bits |
| drivers/iommu/iommufd/Kconfig | Selects the IOMMUFD_DRIVER for enabling tests |
| drivers/crypto/intel/qat/qat_common/adf_gen4_hw_data.h | Updates the interrupt source mask for QAT ring interrupt handling |
| drivers/crypto/intel/qat/qat_common/Makefile | Updates the object file list to reflect QAT migration changes |
Comments suppressed due to low confidence (2)
tools/testing/selftests/iommu/iommufd_utils.h:283
- [nitpick] The local variable name 'bitmap_size' may be confused with previous usage in the function signature. Consider renaming it (e.g. to 'alloc_size') for clarity.
unsigned long bitmap_size = DIV_ROUND_UP(nbits, BITS_PER_BYTE);
drivers/iommu/iommufd/iova_bitmap.c:470
- [nitpick] Consider adding a comment explaining the purpose and expected range of 'set_ahead_length' to improve maintainability and ease future code reviews.
bitmap->set_ahead_length = ((last_bit - cur_bit + 1) << bitmap->mapped.pgshift);
deepin pr auto review代码审查意见:
总的来说,这些更改看起来都是合理的,但是需要确保它们不会引入任何问题,并且与现有的代码库兼容。 |
There was a problem hiding this comment.
Hey @Avenger-285714 - I've reviewed your changes - here's some feedback:
- Ensure that the new set_ahead_length field is explicitly initialized (e.g., in iova_bitmap_create) to zero to prevent accidental use of stale values before any set_ahead calls.
- Since DIV_ROUND_UP is added in the test utils, wrap it in #ifndef or give it a unique prefix to avoid macro collisions with other headers.
- Double-check that moving qat_mig_dev.o into the main intel_qat-objs list doesn’t pull migration code into builds where it’s not needed—consider guarding it behind a CONFIG_QAT_MIGRATION option if appropriate.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| if (*offs < 0 || | ||
| check_add_overflow((loff_t)len, *offs, &end)) | ||
| check_add_overflow(len, *offs, &end)) |
There was a problem hiding this comment.
issue (bug_risk): Removed cast to loff_t may cause incorrect overflow checks
Casting len to loff_t is important for correct signed overflow detection. Using size_t may result in missed or incorrect overflow checks. Please ensure both operands are cast to a consistent type.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: opsiff The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Link: #837
Skip iommu/amd: Set the pgsize_bitmap correctly
Summary by Sourcery
Implement ahead-of-time bit setting in the IOMMUFD IOVA bitmap for live migration, backport Intel QAT migration device support into the in-tree build, and correct related bitmask, overflow, and size calculations across drivers and selftests.
Bug Fixes:
Enhancements:
Build:
Tests: