Skip to contentSkip to conversation

radeon: use kvcalloc for relocs and chunks

PATCH Applied Chen Li 4 participants 4 messages Mar 17, 2021

Subsystems (2)
lore
Share & tools
lore
maintainer Reviewed-by on v2 1/1
#1 lore raw
In reply to Chen Li

Am 17.03.21 um 15:48 schrieb Chen Li:

Quoted 17 lines

kvmalloc_array + __GFP_ZERO is the same with kvcalloc.

As for p->chunks, it will be used in:

```
if (ib_chunk->kdata)
		memcpy(parser->ib.ptr, ib_chunk->kdata, ib_chunk->length_dw * 4);
```

If chunks doesn't zero out with __GFP_ZERO, it may point to somewhere else, e.g.,

```
Unable to handle kernel paging request at virtual address 0000000000010000
...
pc is at memcpy+0x84/0x250
ra is at radeon_cs_ioctl+0x368/0xb90 [radeon]
```
Quoted 3 lines

after allocating chunks with __GFP_KERNEL/kvcalloc, this bug is fixed.

Fixes 3fcb4f01deed ("drm/radeon: Use kvmalloc for CS chunks")
Quoted 24 lines

---

changelog:

   v1->v2: add Fixes: tag
  drivers/gpu/drm/radeon/radeon_cs.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index fb736ef9f9aa..059431689c2d 100644
@@ -93,8 +93,8 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
  	p->dma_reloc_idx = 0;
  	/* FIXME: we assume that each relocs use 4 dwords */
  	p->nrelocs = chunk->length_dw / 4;
-	p->relocs = kvmalloc_array(p->nrelocs, sizeof(struct radeon_bo_list),
-			GFP_KERNEL | __GFP_ZERO);
+	p->relocs = kvcalloc(p->nrelocs, sizeof(struct radeon_bo_list),
+			GFP_KERNEL);
  	if (p->relocs == NULL) {
  		return -ENOMEM;
  	}

drivers/gpu/drm/radeon/radeon_cs.c int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) · line 305

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_cs.c +1 -1
@@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
  	}
  	p->cs_flags = 0;
  	p->nchunks = cs->num_chunks;
-	p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
+	p->chunks = kvcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
  	if (p->chunks == NULL) {
  		return -ENOMEM;
  	}

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Chen Li

author
#0 lore raw

PATCH v2 1/1 radeon: use kvcalloc for relocs and chunks

kvmalloc_array + __GFP_ZERO is the same with kvcalloc.

As for p->chunks, it will be used in:

```
if (ib_chunk->kdata)
		memcpy(parser->ib.ptr, ib_chunk->kdata, ib_chunk->length_dw * 4);
```

If chunks doesn't zero out with __GFP_ZERO, it may point to somewhere else, e.g.,

```
Unable to handle kernel paging request at virtual address 0000000000010000
...
pc is at memcpy+0x84/0x250
ra is at radeon_cs_ioctl+0x368/0xb90 [radeon]
```

after allocating chunks with __GFP_KERNEL/kvcalloc, this bug is fixed.

Fixes 3fcb4f01deed ("drm/radeon: Use kvmalloc for CS chunks")

---

changelog:
v1->v2: add Fixes: tag

 drivers/gpu/drm/radeon/radeon_cs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +3 -3
index fb736ef9f9aa..059431689c2d 100644
@@ -93,8 +93,8 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
 	p->dma_reloc_idx = 0;
 	/* FIXME: we assume that each relocs use 4 dwords */
 	p->nrelocs = chunk->length_dw / 4;
-	p->relocs = kvmalloc_array(p->nrelocs, sizeof(struct radeon_bo_list),
-			GFP_KERNEL | __GFP_ZERO);
+	p->relocs = kvcalloc(p->nrelocs, sizeof(struct radeon_bo_list),
+			GFP_KERNEL);
 	if (p->relocs == NULL) {
 		return -ENOMEM;
 	}
@@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
 	}
 	p->cs_flags = 0;
 	p->nchunks = cs->num_chunks;
-	p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
+	p->chunks = kvcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
 	if (p->chunks == NULL) {
 		return -ENOMEM;
 	}
Signature · 10 lines
2.30.1





_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v2 1/1
#2 lore raw

Am 17.03.21 um 15:48 schrieb Chen Li:

Quoted 17 lines

kvmalloc_array + __GFP_ZERO is the same with kvcalloc.

As for p->chunks, it will be used in:

```
if (ib_chunk->kdata)
		memcpy(parser->ib.ptr, ib_chunk->kdata, ib_chunk->length_dw * 4);
```

If chunks doesn't zero out with __GFP_ZERO, it may point to somewhere else, e.g.,

```
Unable to handle kernel paging request at virtual address 0000000000010000
...
pc is at memcpy+0x84/0x250
ra is at radeon_cs_ioctl+0x368/0xb90 [radeon]
```
Quoted 3 lines

after allocating chunks with __GFP_KERNEL/kvcalloc, this bug is fixed.

Fixes 3fcb4f01deed ("drm/radeon: Use kvmalloc for CS chunks")
Quoted 24 lines

---

changelog:

   v1->v2: add Fixes: tag
  drivers/gpu/drm/radeon/radeon_cs.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index fb736ef9f9aa..059431689c2d 100644
@@ -93,8 +93,8 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
  	p->dma_reloc_idx = 0;
  	/* FIXME: we assume that each relocs use 4 dwords */
  	p->nrelocs = chunk->length_dw / 4;
-	p->relocs = kvmalloc_array(p->nrelocs, sizeof(struct radeon_bo_list),
-			GFP_KERNEL | __GFP_ZERO);
+	p->relocs = kvcalloc(p->nrelocs, sizeof(struct radeon_bo_list),
+			GFP_KERNEL);
  	if (p->relocs == NULL) {
  		return -ENOMEM;
  	}

drivers/gpu/drm/radeon/radeon_cs.c int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) · line 305

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_cs.c +1 -1
@@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
  	}
  	p->cs_flags = 0;
  	p->nchunks = cs->num_chunks;
-	p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
+	p->chunks = kvcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
  	if (p->chunks == NULL) {
  		return -ENOMEM;
  	}

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#3 lore raw

Applied. Thanks!

Alex

Quoted 54 lines · Christian König

Am 17.03.21 um 15:48 schrieb Chen Li:

Quoted 17 lines

kvmalloc_array + __GFP_ZERO is the same with kvcalloc.

As for p->chunks, it will be used in:

```
if (ib_chunk->kdata)
              memcpy(parser->ib.ptr, ib_chunk->kdata, ib_chunk->length_dw * 4);
```

If chunks doesn't zero out with __GFP_ZERO, it may point to somewhere else, e.g.,

```
Unable to handle kernel paging request at virtual address 0000000000010000
...
pc is at memcpy+0x84/0x250
ra is at radeon_cs_ioctl+0x368/0xb90 [radeon]
```
Quoted 3 lines

after allocating chunks with __GFP_KERNEL/kvcalloc, this bug is fixed.

Fixes 3fcb4f01deed ("drm/radeon: Use kvmalloc for CS chunks")
Quoted 29 lines

---

changelog:

   v1->v2: add Fixes: tag
  drivers/gpu/drm/radeon/radeon_cs.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +3 -3
index fb736ef9f9aa..059431689c2d 100644
@@ -93,8 +93,8 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
      p->dma_reloc_idx = 0;
      /* FIXME: we assume that each relocs use 4 dwords */
      p->nrelocs = chunk->length_dw / 4;
-     p->relocs = kvmalloc_array(p->nrelocs, sizeof(struct radeon_bo_list),
-                     GFP_KERNEL | __GFP_ZERO);
+     p->relocs = kvcalloc(p->nrelocs, sizeof(struct radeon_bo_list),
+                     GFP_KERNEL);
      if (p->relocs == NULL) {
              return -ENOMEM;
      }
@@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
      }
      p->cs_flags = 0;
      p->nchunks = cs->num_chunks;
-     p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
+     p->chunks = kvcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL);
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_cs.c int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) · line 305

Quoted 3 lines
drivers/gpu/drm/radeon/radeon_cs.c +0 -0
      if (p->chunks == NULL) {
              return -ENOMEM;
      }

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx