drm/amdgpu: Check BO's requested pinning domains against its preferred_domains
Subsystems (2)
PATCH 1/1 drm/amdgpu: Check BO's requested pinning domains against its preferred_domains
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.
For example, this can happen if the user requests to create a BO in GTT domain for display scanout. amdgpu_dm will allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, in amdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
@@ -883,6 +883,9 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ + domain = bo->preferred_domains & domain; +/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT )
Signature · 1 line
2.37.0
Christian König
maintainerAm 12.07.22 um 00:44 schrieb [email protected]:
Quoted 23 lines
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by
bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.For example, this can happen if the user requests to create a BO in GTT domain for display scanout.
amdgpu_dmwill allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, inamdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.Signed-off-by Leo Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, · line 887
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-0@@ -883,6 +883,9 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ + domain = bo->preferred_domains & domain
Please guard that with an "if (bo->preferred_domains & domain)" to handle the case when the kernel needs to override the pin domain. That can happen when we export a BO to a V4L camera (for example).
Apart from that looks like a rather nice bugfix.
Alex should we add a CC stable to this?
Regards,
Christian.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0+/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT )
Quoted 35 lines · Christian König
Am 12.07.22 um 00:44 schrieb [email protected]:
Quoted 23 lines
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by
bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.For example, this can happen if the user requests to create a BO in GTT domain for display scanout.
amdgpu_dmwill allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, inamdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.Signed-off-by Leo Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, · line 887
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-0@@ -883,6 +883,9 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ + domain = bo->preferred_domains & domainPlease guard that with an "if (
bo->preferred_domains& domain)" to handle the case when the kernel needs to override the pin domain. That can happen when we export a BO to a V4L camera (for example).
Quoted 3 lines
Apart from that looks like a rather nice bugfix.
Alex should we add a CC stable to this?
Yes, I can add a stable tag.
Alex
Quoted 9 lines
Regards,
Christian.Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0+/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT )
PATCH v2 1/1 drm/amdgpu: Check BO's requested pinning domains against its preferred_domains
In reply to [email protected]From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.
For example, this can happen if the user requests to create a BO in GTT domain for display scanout. amdgpu_dm will allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, in amdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.
v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
@@ -883,6 +883,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ +if (bo->preferred_domains & domain) + domain = bo->preferred_domains & domain; +/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT )
Signature · 1 line
2.37.0
Quoted 14 lines · On Tue, Jul 12, 2022 at 12:28 PM <[email protected]> wrote:
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by
bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.For example, this can happen if the user requests to create a BO in GTT domain for display scanout.
amdgpu_dmwill allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, inamdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.
Quoted 4 lines
v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).Signed-off-by Leo Li <[email protected]>
Quoted 22 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -883,6 +883,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ +if (bo->preferred_domains & domain) + domain = bo->preferred_domains & domain; +/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT ) --2.37.0
Quoted 15 lines · Alex Deucher
Quoted 14 lines · On Tue, Jul 12, 2022 at 12:28 PM <[email protected]> wrote:
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by
bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.For example, this can happen if the user requests to create a BO in GTT domain for display scanout.
amdgpu_dmwill allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, inamdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.
Quoted 6 lines
Quoted 4 lines
v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).Signed-off-by Leo Li <[email protected]>Reviewed-by Alex Deucher <[email protected]>
Pushed, thanks!
- Leo
Quoted 23 lines
Quoted 23 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -883,6 +883,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ +if (bo->preferred_domains & domain) + domain = bo->preferred_domains & domain; +/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT ) --2.37.0
Am 12.07.22 um 18:30 schrieb [email protected]:
Quoted 13 lines
From: Leo Li <[email protected]>
When pinning a buffer, we should check to see if there are any additional restrictions imposed by
bo->preferred_domains. This will prevent the BO from being moved to an invalid domain when pinning.For example, this can happen if the user requests to create a BO in GTT domain for display scanout.
amdgpu_dmwill allow pinning to either VRAM or GTT domains, since DCN can scanout from either or. However, inamdgpu_bo_pin_restricted(), pinning to VRAM is preferred if there is adequate carveout. This can lead to pinning to VRAM despite the user requesting GTT placement for the BO.
Quoted 4 lines
v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).Signed-off-by Leo Li <[email protected]>
Quoted 19 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-0@@ -883,6 +883,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (WARN_ON_ONCE (min_offset > max_offset))return -EINVAL ; +/* Check domain to be pinned to against preferred domains */ +if (bo->preferred_domains & domain) + domain = bo->preferred_domains & domain; +/* A shared bo cannot be migrated to VRAM */ if (bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT )