Commit 24fdf894 authored by Longfang Liu's avatar Longfang Liu Committed by JangShui Yang
Browse files

vfio/migration: added map length page alignment

virt inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9DRAC


CVE: NA

----------------------------------------------------------------------

On systems with more than 64KB pages, since the ACC dev BAR2 configuration
space will only map 32KB to the VM, if page alignment is not performed,
the length of the allocated space will fail the length check.

This will cause a VF device to fail to be enabled successfully
on systems with pages above 64KB.

Signed-off-by: default avatarLongfang Liu <liulongfang@huawei.com>
Signed-off-by: default avatarJiangShui Yang <yangjiangshui@h-partners.com>
parent 2a0cdac6
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -1221,7 +1221,21 @@ static int hisi_acc_vfio_pci_mmap(struct vfio_device *core_vdev,
	index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
	if (index == VFIO_PCI_BAR2_REGION_INDEX) {
		u64 req_len, pgoff, req_start;
		resource_size_t end = pci_resource_len(vdev->pdev, index) / 2;
		resource_size_t end;

		/*
		 * ACC VF dev 64KB BAR2 region consists of both functional
		 * register space and migration control register space, each
		 * uses 32KB BAR2 region, on the system with more than 64KB
		 * page size, even if the migration control register space
		 * is written by VM, it will only affects the VF.
		 *
		 * In order to support the live migration function in the
		 * system with a page size above 64KB, the driver needs
		 * to ensure that the VF region size is aligned with the
		 * system page size.
		 */
		end = PAGE_ALIGN(pci_resource_len(vdev->pdev, index) / 2);

		req_len = vma->vm_end - vma->vm_start;
		pgoff = vma->vm_pgoff &