In AMDGPU driver, the bo mapping should always align to CPU page or
the page table is corrupted.
The first patch is cherry-picked from Loongson community, which sets a
suitable dev_info.gart_page_size so Mesa will handle the alignment
correctly.
The second patch is added to ensure an ioctl with unaligned parameter to
be rejected -EINVAL, instead of causing page table corruption.
The patches should be applied for drm-next.
Huacai Chen (1):
drm/amdgpu: Set a suitable dev_info.gart_page_size
Xℹ Ruoyao (1):
drm/amdgpu: check alignment on CPU page for bo map
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
base-commit: a0c8b193bfe81cc8e9c7c162bb8d777ba12596f0
--
2.31.1
From: Huacai Chen <[email protected]>
In Mesa, dev_info.gart_page_size is used for alignment and it was
set to AMDGPU_GPU_PAGE_SIZE(4KB). However, the page table of AMDGPU
driver requires an alignment on CPU pages. So, for non-4KB page system,
gart_page_size should be max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE).
Signed-off-by: Rui Wang <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
Link: https://github.com/loongson-community/linux-stable/commit/caa9c0a1
[Xi: rebased for drm-next, use max_t for checkpatch,
and reworded commit message.]
Signed-off-by: Xi Ruoyao <[email protected]>
BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1549
Tested-by: Dan Horák <[email protected]>
Cc: [email protected]
---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 86eeeb4f3513..3b0be64e4638 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -791,9 +791,9 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
}
- dev_info->virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+ dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
- dev_info->gart_page_size = AMDGPU_GPU_PAGE_SIZE;
+ dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
dev_info->cu_active_number = adev->gfx.cu_info.number;
dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
dev_info->ce_ram_size = adev->gfx.ce_ram_size;
--
2.31.1
The page table of AMDGPU requires an alignment to CPU page so we should
check ioctl parameters for it. Return -EINVAL if some parameter is
unaligned to CPU page, instead of corrupt the page table sliently.
Signed-off-by: Xi Ruoyao <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index dc4d6ae71476..a01c158bc29f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2198,8 +2198,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
uint64_t eaddr;
/* validate the parameters */
- if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK ||
- size == 0 || size & AMDGPU_GPU_PAGE_MASK)
+ if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
+ size == 0 || size & ~PAGE_MASK)
return -EINVAL;
/* make sure object fit at this offset */
@@ -2264,8 +2264,8 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
int r;
/* validate the parameters */
- if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK ||
- size == 0 || size & AMDGPU_GPU_PAGE_MASK)
+ if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
+ size == 0 || size & ~PAGE_MASK)
return -EINVAL;
/* make sure object fit at this offset */
--
2.31.1
Reviewed-by: Christian König <[email protected]> for the entire
series.
Alex will probably pick them up for the next feature pull request.
Regards,
Christian.
Am 30.03.21 um 17:33 schrieb Xℹ Ruoyao:
> In AMDGPU driver, the bo mapping should always align to CPU page or
> the page table is corrupted.
>
> The first patch is cherry-picked from Loongson community, which sets a
> suitable dev_info.gart_page_size so Mesa will handle the alignment
> correctly.
>
> The second patch is added to ensure an ioctl with unaligned parameter to
> be rejected -EINVAL, instead of causing page table corruption.
>
> The patches should be applied for drm-next.
>
> Huacai Chen (1):
> drm/amdgpu: Set a suitable dev_info.gart_page_size
>
> Xℹ Ruoyao (1):
> drm/amdgpu: check alignment on CPU page for bo map
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
>
> base-commit: a0c8b193bfe81cc8e9c7c162bb8d777ba12596f0
Applied. Thanks!
Alex
On Tue, Mar 30, 2021 at 12:21 PM Christian König
<[email protected]> wrote:
>
> Reviewed-by: Christian König <[email protected]> for the entire
> series.
>
> Alex will probably pick them up for the next feature pull request.
>
> Regards,
> Christian.
>
> Am 30.03.21 um 17:33 schrieb Xℹ Ruoyao:
> > In AMDGPU driver, the bo mapping should always align to CPU page or
> > the page table is corrupted.
> >
> > The first patch is cherry-picked from Loongson community, which sets a
> > suitable dev_info.gart_page_size so Mesa will handle the alignment
> > correctly.
> >
> > The second patch is added to ensure an ioctl with unaligned parameter to
> > be rejected -EINVAL, instead of causing page table corruption.
> >
> > The patches should be applied for drm-next.
> >
> > Huacai Chen (1):
> > drm/amdgpu: Set a suitable dev_info.gart_page_size
> >
> > Xℹ Ruoyao (1):
> > drm/amdgpu: check alignment on CPU page for bo map
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
> > 2 files changed, 6 insertions(+), 6 deletions(-)
> >
> >
> > base-commit: a0c8b193bfe81cc8e9c7c162bb8d777ba12596f0
>
> _______________________________________________
> amd-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx