Skip to contentSkip to conversation

drm/amdgpu: Check BO's requested pinning domains against its preferred_domains

PATCH Superseded [email protected] 4 participants 7 messages Jul 11, 2022 – Jul 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 8a7b0f6162da..50400d70ef12 100644
@@ -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
maintainer
#1 lore raw

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_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 +0 -0
index 8a7b0f6162da..50400d70ef12 100644

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)
#2 lore raw
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_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 +0 -0
index 8a7b0f6162da..50400d70ef12 100644

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).

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)
#3 lore raw

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
index 8a7b0f6162da..bbd3b8b14cfb 100644
@@ -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
Reviewed-by on v2 1/1
#4 lore raw
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_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.

Quoted 4 lines

v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).

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
index 8a7b0f6162da..bbd3b8b14cfb 100644
@@ -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

author
#5 lore raw
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_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.

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).

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
index 8a7b0f6162da..bbd3b8b14cfb 100644
@@ -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

Reviewed-by on v2 1/1
#6 lore raw
In reply to [email protected]

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_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.

Quoted 4 lines

v2: Allow the kernel to override the domain, which can happen when
exporting a BO to a V4L camera (for example).

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
index 8a7b0f6162da..bbd3b8b14cfb 100644
@@ -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)