AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-17  2:26 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
@ 2023-07-17  2:26 ` Guchun Chen
  2023-07-17 14:58   ` Felix Kuehling
  0 siblings, 1 reply; 9+ messages in thread
From: Guchun Chen @ 2023-07-17  2:26 UTC (permalink / raw)
  To: amd-gfx, alexander.deucher, hawking.zhang, christian.koenig,
	Philip.Yang, Felix.Kuehling
  Cc: Guchun Chen

~0 as no xcp partition is used in several places, so improve its
definition by a macro for code consistency.

Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Guchun Chen <guchun.chen@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a7f314ddd173..d34c3ef8f3ed 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1709,7 +1709,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 			alloc_flags |= (flags & KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
 			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
 		}
-		xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
+		xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+					0 : fpriv->xcp_id;
 	} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
 		domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
 		alloc_flags = 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
index d175e862f222..9c9cca129498 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
@@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
 	if (!adev->xcp_mgr)
 		return 0;
 
-	fpriv->xcp_id = ~0;
+	fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
 	for (i = 0; i < MAX_XCP; ++i) {
 		if (!adev->xcp_mgr->xcp[i].ddev)
 			break;
@@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
 		}
 	}
 
-	fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
+	fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ? -1 :
 				adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
 	return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
index 0f8026d64ea5..9a1036aeec2a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
@@ -37,6 +37,8 @@
 #define AMDGPU_XCP_FL_NONE 0
 #define AMDGPU_XCP_FL_LOCKED (1 << 0)
 
+#define AMDGPU_XCP_NO_PARTITION (~0)
+
 struct amdgpu_fpriv;
 
 enum AMDGPU_XCP_IP_BLOCK {
diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
index 16471b81a1f5..72b629a78c62 100644
--- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
+++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
@@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct amdgpu_device *adev,
 	enum AMDGPU_XCP_IP_BLOCK ip_blk;
 	uint32_t inst_mask;
 
-	ring->xcp_id = ~0;
+	ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
 	if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
 		return;
 
@@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
 	u32 sel_xcp_id;
 	int i;
 
-	if (fpriv->xcp_id == ~0) {
+	if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
 		u32 least_ref_cnt = ~0;
 
 		fpriv->xcp_id = 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-17  2:26 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
@ 2023-07-17 14:58   ` Felix Kuehling
  2023-07-18  2:16     ` Chen, Guchun
  0 siblings, 1 reply; 9+ messages in thread
From: Felix Kuehling @ 2023-07-17 14:58 UTC (permalink / raw)
  To: Guchun Chen, amd-gfx, alexander.deucher, hawking.zhang,
	christian.koenig, Philip.Yang

On 2023-07-16 22:26, Guchun Chen wrote:
> ~0 as no xcp partition is used in several places, so improve its
> definition by a macro for code consistency.
>
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Guchun Chen <guchun.chen@amd.com>

The series is

Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>


> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
>   drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
>   4 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index a7f314ddd173..d34c3ef8f3ed 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1709,7 +1709,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
>   			alloc_flags |= (flags & KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
>   			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
>   		}
> -		xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
> +		xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
> +					0 : fpriv->xcp_id;
>   	} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
>   		domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
>   		alloc_flags = 0;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> index d175e862f222..9c9cca129498 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> @@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
>   	if (!adev->xcp_mgr)
>   		return 0;
>   
> -	fpriv->xcp_id = ~0;
> +	fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
>   	for (i = 0; i < MAX_XCP; ++i) {
>   		if (!adev->xcp_mgr->xcp[i].ddev)
>   			break;
> @@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
>   		}
>   	}
>   
> -	fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
> +	fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ? -1 :
>   				adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
>   	return 0;
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> index 0f8026d64ea5..9a1036aeec2a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> @@ -37,6 +37,8 @@
>   #define AMDGPU_XCP_FL_NONE 0
>   #define AMDGPU_XCP_FL_LOCKED (1 << 0)
>   
> +#define AMDGPU_XCP_NO_PARTITION (~0)
> +
>   struct amdgpu_fpriv;
>   
>   enum AMDGPU_XCP_IP_BLOCK {
> diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> index 16471b81a1f5..72b629a78c62 100644
> --- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> +++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> @@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct amdgpu_device *adev,
>   	enum AMDGPU_XCP_IP_BLOCK ip_blk;
>   	uint32_t inst_mask;
>   
> -	ring->xcp_id = ~0;
> +	ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
>   	if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
>   		return;
>   
> @@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
>   	u32 sel_xcp_id;
>   	int i;
>   
> -	if (fpriv->xcp_id == ~0) {
> +	if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
>   		u32 least_ref_cnt = ~0;
>   
>   		fpriv->xcp_id = 0;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-17 14:58   ` Felix Kuehling
@ 2023-07-18  2:16     ` Chen, Guchun
  2023-08-03  8:28       ` Christian König
  0 siblings, 1 reply; 9+ messages in thread
From: Chen, Guchun @ 2023-07-18  2:16 UTC (permalink / raw)
  To: Kuehling, Felix, amd-gfx@lists.freedesktop.org,
	Deucher, Alexander, Zhang, Hawking, Koenig, Christian,
	Yang, Philip

[Public]

Thank you for review, Felix.

Hi Christian,

I forgot to add your RB in patch 2/patch3 when posting this series for review. I will add it back when pushing. Hope it's fine to you.

Regards,
Guchun

> -----Original Message-----
> From: Kuehling, Felix <Felix.Kuehling@amd.com>
> Sent: Monday, July 17, 2023 10:58 PM
> To: Chen, Guchun <Guchun.Chen@amd.com>; amd-
> gfx@lists.freedesktop.org; Deucher, Alexander
> <Alexander.Deucher@amd.com>; Zhang, Hawking
> <Hawking.Zhang@amd.com>; Koenig, Christian
> <Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com>
> Subject: Re: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp
> partition case
>
> On 2023-07-16 22:26, Guchun Chen wrote:
> > ~0 as no xcp partition is used in several places, so improve its
> > definition by a macro for code consistency.
> >
> > Suggested-by: Christian König <christian.koenig@amd.com>
> > Signed-off-by: Guchun Chen <guchun.chen@amd.com>
>
> The series is
>
> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
>
>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
> >   drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
> >   4 files changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > index a7f314ddd173..d34c3ef8f3ed 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > @@ -1709,7 +1709,8 @@ int
> amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
> >                     alloc_flags |= (flags &
> KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
> >                     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
> >             }
> > -           xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
> > +           xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
> > +                                   0 : fpriv->xcp_id;
> >     } else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
> >             domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
> >             alloc_flags = 0;
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> > index d175e862f222..9c9cca129498 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> > @@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct
> amdgpu_device *adev,
> >     if (!adev->xcp_mgr)
> >             return 0;
> >
> > -   fpriv->xcp_id = ~0;
> > +   fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
> >     for (i = 0; i < MAX_XCP; ++i) {
> >             if (!adev->xcp_mgr->xcp[i].ddev)
> >                     break;
> > @@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct
> amdgpu_device *adev,
> >             }
> >     }
> >
> > -   fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
> > +   fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
> -1 :
> >                             adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
> >     return 0;
> >   }
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> > index 0f8026d64ea5..9a1036aeec2a 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> > @@ -37,6 +37,8 @@
> >   #define AMDGPU_XCP_FL_NONE 0
> >   #define AMDGPU_XCP_FL_LOCKED (1 << 0)
> >
> > +#define AMDGPU_XCP_NO_PARTITION (~0)
> > +
> >   struct amdgpu_fpriv;
> >
> >   enum AMDGPU_XCP_IP_BLOCK {
> > diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> > b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> > index 16471b81a1f5..72b629a78c62 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> > @@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct
> amdgpu_device *adev,
> >     enum AMDGPU_XCP_IP_BLOCK ip_blk;
> >     uint32_t inst_mask;
> >
> > -   ring->xcp_id = ~0;
> > +   ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
> >     if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
> >             return;
> >
> > @@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
> >     u32 sel_xcp_id;
> >     int i;
> >
> > -   if (fpriv->xcp_id == ~0) {
> > +   if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
> >             u32 least_ref_cnt = ~0;
> >
> >             fpriv->xcp_id = 0;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition
@ 2023-07-18  5:13 Guchun Chen
  2023-07-18  5:13 ` [PATCH 2/4] drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create Guchun Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Guchun Chen @ 2023-07-18  5:13 UTC (permalink / raw)
  To: amd-gfx, alexander.deucher, hawking.zhang, christian.koenig,
	Philip.Yang, Felix.Kuehling
  Cc: Guchun Chen

file_priv needs to be setup firstly, otherwise, root PD
will always be allocated on partition 0, even if opening
the device from other partitions.

Fixes: ffc6deb773f7 ("drm/amdkfd: Store xcp partition id to amdgpu bo")
Signed-off-by: Guchun Chen <guchun.chen@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 85a0d5f419c8..53a024cf0544 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1232,13 +1232,13 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		pasid = 0;
 	}
 
-	r = amdgpu_vm_init(adev, &fpriv->vm);
+	r = amdgpu_xcp_open_device(adev, fpriv, file_priv);
 	if (r)
 		goto error_pasid;
 
-	r = amdgpu_xcp_open_device(adev, fpriv, file_priv);
+	r = amdgpu_vm_init(adev, &fpriv->vm);
 	if (r)
-		goto error_vm;
+		goto error_pasid;
 
 	r = amdgpu_vm_set_pasid(adev, &fpriv->vm, pasid);
 	if (r)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create
  2023-07-18  5:13 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
@ 2023-07-18  5:13 ` Guchun Chen
  2023-07-18  5:13 ` [PATCH 3/4] drm/amdgpu/vm: use the same xcp_id from root PD Guchun Chen
  2023-07-18  5:13 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
  2 siblings, 0 replies; 9+ messages in thread
From: Guchun Chen @ 2023-07-18  5:13 UTC (permalink / raw)
  To: amd-gfx, alexander.deucher, hawking.zhang, christian.koenig,
	Philip.Yang, Felix.Kuehling
  Cc: Mikhail Gavrilov, Guchun Chen

Recent code set xcp_id stored from file private data when opening
device to amdgpu bo for accounting memory usage etc, but not all
VMs are attached to this fpriv structure like the vm cases in
amdgpu_mes_self_test, otherwise, KASAN will complain below out
of bound access. And more importantly, VM code should not touch
fpriv structure, so drop fpriv code handling from amdgpu_vm_pt.

[   77.292314] BUG: KASAN: slab-out-of-bounds in amdgpu_vm_pt_create+0x17e/0x4b0 [amdgpu]
[   77.293845] Read of size 4 at addr ffff888102c48a48 by task modprobe/1069
[   77.294146] Call Trace:
[   77.294178]  <TASK>
[   77.294208]  dump_stack_lvl+0x49/0x63
[   77.294260]  print_report+0x16f/0x4a6
[   77.294307]  ? amdgpu_vm_pt_create+0x17e/0x4b0 [amdgpu]
[   77.295979]  ? kasan_complete_mode_report_info+0x3c/0x200
[   77.296057]  ? amdgpu_vm_pt_create+0x17e/0x4b0 [amdgpu]
[   77.297556]  kasan_report+0xb4/0x130
[   77.297609]  ? amdgpu_vm_pt_create+0x17e/0x4b0 [amdgpu]
[   77.299202]  __asan_load4+0x6f/0x90
[   77.299272]  amdgpu_vm_pt_create+0x17e/0x4b0 [amdgpu]
[   77.300796]  ? amdgpu_init+0x6e/0x1000 [amdgpu]
[   77.302222]  ? amdgpu_vm_pt_clear+0x750/0x750 [amdgpu]
[   77.303721]  ? preempt_count_sub+0x18/0xc0
[   77.303786]  amdgpu_vm_init+0x39e/0x870 [amdgpu]
[   77.305186]  ? amdgpu_vm_wait_idle+0x90/0x90 [amdgpu]
[   77.306683]  ? kasan_set_track+0x25/0x30
[   77.306737]  ? kasan_save_alloc_info+0x1b/0x30
[   77.306795]  ? __kasan_kmalloc+0x87/0xa0
[   77.306852]  amdgpu_mes_self_test+0x169/0x620 [amdgpu]

v2: without specifying xcp partition for PD/PT bo, the xcp id is -1.

Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2686
Fixes: ffc6deb773f7 ("drm/amdkfd: Store xcp partition id to amdgpu bo")
Signed-off-by: Guchun Chen <guchun.chen@amd.com>
Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 11 ++++++-----
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 53a024cf0544..cab2fdd5b76a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1236,7 +1236,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	if (r)
 		goto error_pasid;
 
-	r = amdgpu_vm_init(adev, &fpriv->vm);
+	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
 	if (r)
 		goto error_pasid;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
index e9091ebfe230..f808841310fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
@@ -1382,7 +1382,7 @@ int amdgpu_mes_self_test(struct amdgpu_device *adev)
 		goto error_pasid;
 	}
 
-	r = amdgpu_vm_init(adev, vm);
+	r = amdgpu_vm_init(adev, vm, -1);
 	if (r) {
 		DRM_ERROR("failed to initialize vm\n");
 		goto error_pasid;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 32adc31c093d..74380b21e7a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2121,13 +2121,14 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
  *
  * @adev: amdgpu_device pointer
  * @vm: requested vm
+ * @xcp_id: GPU partition selection id
  *
  * Init @vm fields.
  *
  * Returns:
  * 0 for success, error for failure.
  */
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id)
 {
 	struct amdgpu_bo *root_bo;
 	struct amdgpu_bo_vm *root;
@@ -2177,7 +2178,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	vm->evicting = false;
 
 	r = amdgpu_vm_pt_create(adev, vm, adev->vm_manager.root_level,
-				false, &root);
+				false, &root, xcp_id);
 	if (r)
 		goto error_free_delayed;
 	root_bo = &root->bo;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 88ee4507f6b6..bca258c38919 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -398,7 +398,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			u32 pasid);
 
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
 int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_release_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
@@ -481,7 +481,8 @@ void amdgpu_vm_get_memory(struct amdgpu_vm *vm,
 int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		       struct amdgpu_bo_vm *vmbo, bool immediate);
 int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			int level, bool immediate, struct amdgpu_bo_vm **vmbo);
+			int level, bool immediate, struct amdgpu_bo_vm **vmbo,
+			int32_t xcp_id);
 void amdgpu_vm_pt_free_root(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 bool amdgpu_vm_pt_is_root_clean(struct amdgpu_device *adev,
 				struct amdgpu_vm *vm);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index 70fc5856a5b9..eb52dfe64948 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -498,11 +498,12 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  * @level: the page table level
  * @immediate: use a immediate update
  * @vmbo: pointer to the buffer object pointer
+ * @xcp_id: GPU partition id
  */
 int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			int level, bool immediate, struct amdgpu_bo_vm **vmbo)
+			int level, bool immediate, struct amdgpu_bo_vm **vmbo,
+			int32_t xcp_id)
 {
-	struct amdgpu_fpriv *fpriv = container_of(vm, struct amdgpu_fpriv, vm);
 	struct amdgpu_bo_param bp;
 	struct amdgpu_bo *bo;
 	struct dma_resv *resv;
@@ -535,7 +536,7 @@ int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	bp.type = ttm_bo_type_kernel;
 	bp.no_wait_gpu = immediate;
-	bp.xcp_id_plus1 = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id + 1;
+	bp.xcp_id_plus1 = xcp_id + 1;
 
 	if (vm->root.bo)
 		bp.resv = vm->root.bo->tbo.base.resv;
@@ -561,7 +562,7 @@ int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	bp.type = ttm_bo_type_kernel;
 	bp.resv = bo->tbo.base.resv;
 	bp.bo_ptr_size = sizeof(struct amdgpu_bo);
-	bp.xcp_id_plus1 = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id + 1;
+	bp.xcp_id_plus1 = xcp_id + 1;
 
 	r = amdgpu_bo_create(adev, &bp, &(*vmbo)->shadow);
 
@@ -606,7 +607,7 @@ static int amdgpu_vm_pt_alloc(struct amdgpu_device *adev,
 		return 0;
 
 	amdgpu_vm_eviction_unlock(vm);
-	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
+	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt, 0);
 	amdgpu_vm_eviction_lock(vm);
 	if (r)
 		return r;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] drm/amdgpu/vm: use the same xcp_id from root PD
  2023-07-18  5:13 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
  2023-07-18  5:13 ` [PATCH 2/4] drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create Guchun Chen
@ 2023-07-18  5:13 ` Guchun Chen
  2023-07-18  5:13 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
  2 siblings, 0 replies; 9+ messages in thread
From: Guchun Chen @ 2023-07-18  5:13 UTC (permalink / raw)
  To: amd-gfx, alexander.deucher, hawking.zhang, christian.koenig,
	Philip.Yang, Felix.Kuehling
  Cc: Guchun Chen

Other PDs/PTs allocation should just use the same xcp_id as that
stored in root PD.

Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Guchun Chen <guchun.chen@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index eb52dfe64948..83e1923f6775 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -607,7 +607,8 @@ static int amdgpu_vm_pt_alloc(struct amdgpu_device *adev,
 		return 0;
 
 	amdgpu_vm_eviction_unlock(vm);
-	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt, 0);
+	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt,
+				vm->root.bo->xcp_id);
 	amdgpu_vm_eviction_lock(vm);
 	if (r)
 		return r;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-18  5:13 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
  2023-07-18  5:13 ` [PATCH 2/4] drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create Guchun Chen
  2023-07-18  5:13 ` [PATCH 3/4] drm/amdgpu/vm: use the same xcp_id from root PD Guchun Chen
@ 2023-07-18  5:13 ` Guchun Chen
  2023-08-08  6:30   ` Christian König
  2 siblings, 1 reply; 9+ messages in thread
From: Guchun Chen @ 2023-07-18  5:13 UTC (permalink / raw)
  To: amd-gfx, alexander.deucher, hawking.zhang, christian.koenig,
	Philip.Yang, Felix.Kuehling
  Cc: Guchun Chen

~0 as no xcp partition is used in several places, so improve its
definition by a macro for code consistency.

Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Guchun Chen <guchun.chen@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a7f314ddd173..d34c3ef8f3ed 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1709,7 +1709,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 			alloc_flags |= (flags & KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
 			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
 		}
-		xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
+		xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+					0 : fpriv->xcp_id;
 	} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
 		domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
 		alloc_flags = 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
index d175e862f222..9c9cca129498 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
@@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
 	if (!adev->xcp_mgr)
 		return 0;
 
-	fpriv->xcp_id = ~0;
+	fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
 	for (i = 0; i < MAX_XCP; ++i) {
 		if (!adev->xcp_mgr->xcp[i].ddev)
 			break;
@@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
 		}
 	}
 
-	fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
+	fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ? -1 :
 				adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
 	return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
index 0f8026d64ea5..9a1036aeec2a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
@@ -37,6 +37,8 @@
 #define AMDGPU_XCP_FL_NONE 0
 #define AMDGPU_XCP_FL_LOCKED (1 << 0)
 
+#define AMDGPU_XCP_NO_PARTITION (~0)
+
 struct amdgpu_fpriv;
 
 enum AMDGPU_XCP_IP_BLOCK {
diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
index 16471b81a1f5..72b629a78c62 100644
--- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
+++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
@@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct amdgpu_device *adev,
 	enum AMDGPU_XCP_IP_BLOCK ip_blk;
 	uint32_t inst_mask;
 
-	ring->xcp_id = ~0;
+	ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
 	if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
 		return;
 
@@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
 	u32 sel_xcp_id;
 	int i;
 
-	if (fpriv->xcp_id == ~0) {
+	if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
 		u32 least_ref_cnt = ~0;
 
 		fpriv->xcp_id = 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-18  2:16     ` Chen, Guchun
@ 2023-08-03  8:28       ` Christian König
  0 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2023-08-03  8:28 UTC (permalink / raw)
  To: Chen, Guchun, Kuehling, Felix, amd-gfx@lists.freedesktop.org,
	Deucher, Alexander, Zhang, Hawking, Koenig, Christian,
	Yang, Philip

Yeah, perfectly fine for me. I was out of office for a few days as well.

Christian.

Am 18.07.23 um 04:16 schrieb Chen, Guchun:
> [Public]
>
> Thank you for review, Felix.
>
> Hi Christian,
>
> I forgot to add your RB in patch 2/patch3 when posting this series for review. I will add it back when pushing. Hope it's fine to you.
>
> Regards,
> Guchun
>
>> -----Original Message-----
>> From: Kuehling, Felix <Felix.Kuehling@amd.com>
>> Sent: Monday, July 17, 2023 10:58 PM
>> To: Chen, Guchun <Guchun.Chen@amd.com>; amd-
>> gfx@lists.freedesktop.org; Deucher, Alexander
>> <Alexander.Deucher@amd.com>; Zhang, Hawking
>> <Hawking.Zhang@amd.com>; Koenig, Christian
>> <Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com>
>> Subject: Re: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp
>> partition case
>>
>> On 2023-07-16 22:26, Guchun Chen wrote:
>>> ~0 as no xcp partition is used in several places, so improve its
>>> definition by a macro for code consistency.
>>>
>>> Suggested-by: Christian König <christian.koenig@amd.com>
>>> Signed-off-by: Guchun Chen <guchun.chen@amd.com>
>> The series is
>>
>> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
>>
>>
>>> ---
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
>>>    drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
>>>    4 files changed, 8 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> index a7f314ddd173..d34c3ef8f3ed 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> @@ -1709,7 +1709,8 @@ int
>> amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
>>>                      alloc_flags |= (flags &
>> KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
>>>                      AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
>>>              }
>>> -           xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
>>> +           xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
>>> +                                   0 : fpriv->xcp_id;
>>>      } else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
>>>              domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
>>>              alloc_flags = 0;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
>>> index d175e862f222..9c9cca129498 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
>>> @@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct
>> amdgpu_device *adev,
>>>      if (!adev->xcp_mgr)
>>>              return 0;
>>>
>>> -   fpriv->xcp_id = ~0;
>>> +   fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
>>>      for (i = 0; i < MAX_XCP; ++i) {
>>>              if (!adev->xcp_mgr->xcp[i].ddev)
>>>                      break;
>>> @@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct
>> amdgpu_device *adev,
>>>              }
>>>      }
>>>
>>> -   fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
>>> +   fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
>> -1 :
>>>                              adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
>>>      return 0;
>>>    }
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
>>> index 0f8026d64ea5..9a1036aeec2a 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
>>> @@ -37,6 +37,8 @@
>>>    #define AMDGPU_XCP_FL_NONE 0
>>>    #define AMDGPU_XCP_FL_LOCKED (1 << 0)
>>>
>>> +#define AMDGPU_XCP_NO_PARTITION (~0)
>>> +
>>>    struct amdgpu_fpriv;
>>>
>>>    enum AMDGPU_XCP_IP_BLOCK {
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
>>> b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
>>> index 16471b81a1f5..72b629a78c62 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
>>> @@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct
>> amdgpu_device *adev,
>>>      enum AMDGPU_XCP_IP_BLOCK ip_blk;
>>>      uint32_t inst_mask;
>>>
>>> -   ring->xcp_id = ~0;
>>> +   ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
>>>      if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
>>>              return;
>>>
>>> @@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
>>>      u32 sel_xcp_id;
>>>      int i;
>>>
>>> -   if (fpriv->xcp_id == ~0) {
>>> +   if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
>>>              u32 least_ref_cnt = ~0;
>>>
>>>              fpriv->xcp_id = 0;


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case
  2023-07-18  5:13 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
@ 2023-08-08  6:30   ` Christian König
  0 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2023-08-08  6:30 UTC (permalink / raw)
  To: Guchun Chen, amd-gfx, alexander.deucher, hawking.zhang,
	christian.koenig, Philip.Yang, Felix.Kuehling

Am 18.07.23 um 07:13 schrieb Guchun Chen:
> ~0 as no xcp partition is used in several places, so improve its
> definition by a macro for code consistency.
>
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Guchun Chen <guchun.chen@amd.com>
> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>

I guess you already pushed this, so just for the record: Reviewed-by: 
Christian König <christian.koenig@amd.com>.

I need to get faster catching up on mails,
Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c          | 4 ++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h          | 2 ++
>   drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c       | 4 ++--
>   4 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index a7f314ddd173..d34c3ef8f3ed 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1709,7 +1709,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
>   			alloc_flags |= (flags & KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
>   			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED : 0;
>   		}
> -		xcp_id = fpriv->xcp_id == ~0 ? 0 : fpriv->xcp_id;
> +		xcp_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ?
> +					0 : fpriv->xcp_id;
>   	} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
>   		domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
>   		alloc_flags = 0;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> index d175e862f222..9c9cca129498 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> @@ -363,7 +363,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
>   	if (!adev->xcp_mgr)
>   		return 0;
>   
> -	fpriv->xcp_id = ~0;
> +	fpriv->xcp_id = AMDGPU_XCP_NO_PARTITION;
>   	for (i = 0; i < MAX_XCP; ++i) {
>   		if (!adev->xcp_mgr->xcp[i].ddev)
>   			break;
> @@ -381,7 +381,7 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,
>   		}
>   	}
>   
> -	fpriv->vm.mem_id = fpriv->xcp_id == ~0 ? -1 :
> +	fpriv->vm.mem_id = fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION ? -1 :
>   				adev->xcp_mgr->xcp[fpriv->xcp_id].mem_id;
>   	return 0;
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> index 0f8026d64ea5..9a1036aeec2a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
> @@ -37,6 +37,8 @@
>   #define AMDGPU_XCP_FL_NONE 0
>   #define AMDGPU_XCP_FL_LOCKED (1 << 0)
>   
> +#define AMDGPU_XCP_NO_PARTITION (~0)
> +
>   struct amdgpu_fpriv;
>   
>   enum AMDGPU_XCP_IP_BLOCK {
> diff --git a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> index 16471b81a1f5..72b629a78c62 100644
> --- a/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> +++ b/drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c
> @@ -68,7 +68,7 @@ static void aqua_vanjaram_set_xcp_id(struct amdgpu_device *adev,
>   	enum AMDGPU_XCP_IP_BLOCK ip_blk;
>   	uint32_t inst_mask;
>   
> -	ring->xcp_id = ~0;
> +	ring->xcp_id = AMDGPU_XCP_NO_PARTITION;
>   	if (adev->xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
>   		return;
>   
> @@ -177,7 +177,7 @@ static int aqua_vanjaram_select_scheds(
>   	u32 sel_xcp_id;
>   	int i;
>   
> -	if (fpriv->xcp_id == ~0) {
> +	if (fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION) {
>   		u32 least_ref_cnt = ~0;
>   
>   		fpriv->xcp_id = 0;


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-08-08  6:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18  5:13 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
2023-07-18  5:13 ` [PATCH 2/4] drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create Guchun Chen
2023-07-18  5:13 ` [PATCH 3/4] drm/amdgpu/vm: use the same xcp_id from root PD Guchun Chen
2023-07-18  5:13 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
2023-08-08  6:30   ` Christian König
  -- strict thread matches above, loose matches on Subject: below --
2023-07-17  2:26 [PATCH 1/4] drm/amdgpu: Allocate root PD on correct partition Guchun Chen
2023-07-17  2:26 ` [PATCH 4/4] drm/amdgpu: use a macro to define no xcp partition case Guchun Chen
2023-07-17 14:58   ` Felix Kuehling
2023-07-18  2:16     ` Chen, Guchun
2023-08-03  8:28       ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox