* [PATCH v2 03/24] drm/gud: use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
@ 2023-06-27 14:43 ` Julia Lawall
2023-07-03 12:23 ` Thomas Zimmermann
2023-07-04 10:41 ` Noralf Trønnes
2023-06-27 14:43 ` [PATCH v2 06/24] dma-buf: system_heap: " Julia Lawall
` (5 subsequent siblings)
6 siblings, 2 replies; 12+ messages in thread
From: Julia Lawall @ 2023-06-27 14:43 UTC (permalink / raw)
To: Noralf Trønnes
Cc: keescook, kernel-janitors, linux-kernel, dri-devel,
christophe.jaillet, kuba
Use vmalloc_array and vcalloc to protect against
multiplication overflows.
The changes were done using the following Coccinelle
semantic patch:
// <smpl>
@initialize:ocaml@
@@
let rename alloc =
match alloc with
"vmalloc" -> "vmalloc_array"
| "vzalloc" -> "vcalloc"
| _ -> failwith "unknown"
@@
size_t e1,e2;
constant C1, C2;
expression E1, E2, COUNT, x1, x2, x3;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@
(
alloc(x1*x2*x3)
|
alloc(C1 * C2)
|
alloc((sizeof(t)) * (COUNT), ...)
|
- alloc((e1) * (e2))
+ realloc(e1, e2)
|
- alloc((e1) * (COUNT))
+ realloc(COUNT, e1)
|
- alloc((E1) * (E2))
+ realloc(E1, E2)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is. Two patches are thus dropped from the series.
drivers/gpu/drm/gud/gud_pipe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
--- a/drivers/gpu/drm/gud/gud_pipe.c
+++ b/drivers/gpu/drm/gud/gud_pipe.c
@@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu
mutex_lock(&gdrm->damage_lock);
if (!gdrm->shadow_buf) {
- gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height);
+ gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height);
if (!gdrm->shadow_buf) {
mutex_unlock(&gdrm->damage_lock);
return -ENOMEM;
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 03/24] drm/gud: use vmalloc_array and vcalloc
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
@ 2023-07-03 12:23 ` Thomas Zimmermann
2023-07-04 10:41 ` Noralf Trønnes
1 sibling, 0 replies; 12+ messages in thread
From: Thomas Zimmermann @ 2023-07-03 12:23 UTC (permalink / raw)
To: Julia Lawall, Noralf Trønnes
Cc: keescook, kernel-janitors, linux-kernel, dri-devel,
christophe.jaillet, kuba
[-- Attachment #1.1: Type: text/plain, Size: 2197 bytes --]
Am 27.06.23 um 16:43 schrieb Julia Lawall:
> Use vmalloc_array and vcalloc to protect against
> multiplication overflows.
>
> The changes were done using the following Coccinelle
> semantic patch:
>
> // <smpl>
> @initialize:ocaml@
> @@
>
> let rename alloc =
> match alloc with
> "vmalloc" -> "vmalloc_array"
> | "vzalloc" -> "vcalloc"
> | _ -> failwith "unknown"
>
> @@
> size_t e1,e2;
> constant C1, C2;
> expression E1, E2, COUNT, x1, x2, x3;
> typedef u8;
> typedef __u8;
> type t = {u8,__u8,char,unsigned char};
> identifier alloc = {vmalloc,vzalloc};
> fresh identifier realloc = script:ocaml(alloc) { rename alloc };
> @@
>
> (
> alloc(x1*x2*x3)
> |
> alloc(C1 * C2)
> |
> alloc((sizeof(t)) * (COUNT), ...)
> |
> - alloc((e1) * (e2))
> + realloc(e1, e2)
> |
> - alloc((e1) * (COUNT))
> + realloc(COUNT, e1)
> |
> - alloc((E1) * (E2))
> + realloc(E1, E2)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>
> ---
> v2: Use vmalloc_array and vcalloc instead of array_size.
> This also leaves a multiplication of a constant by a sizeof
> as is. Two patches are thus dropped from the series.
>
> drivers/gpu/drm/gud/gud_pipe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
> --- a/drivers/gpu/drm/gud/gud_pipe.c
> +++ b/drivers/gpu/drm/gud/gud_pipe.c
> @@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu
> mutex_lock(&gdrm->damage_lock);
>
> if (!gdrm->shadow_buf) {
> - gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height);
> + gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height);
> if (!gdrm->shadow_buf) {
> mutex_unlock(&gdrm->damage_lock);
> return -ENOMEM;
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 03/24] drm/gud: use vmalloc_array and vcalloc
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
2023-07-03 12:23 ` Thomas Zimmermann
@ 2023-07-04 10:41 ` Noralf Trønnes
1 sibling, 0 replies; 12+ messages in thread
From: Noralf Trønnes @ 2023-07-04 10:41 UTC (permalink / raw)
To: Julia Lawall
Cc: keescook, kernel-janitors, linux-kernel, dri-devel, noralf,
christophe.jaillet, kuba
On 6/27/23 16:43, Julia Lawall wrote:
> Use vmalloc_array and vcalloc to protect against
> multiplication overflows.
>
> The changes were done using the following Coccinelle
> semantic patch:
>
> // <smpl>
> @initialize:ocaml@
> @@
>
> let rename alloc =
> match alloc with
> "vmalloc" -> "vmalloc_array"
> | "vzalloc" -> "vcalloc"
> | _ -> failwith "unknown"
>
> @@
> size_t e1,e2;
> constant C1, C2;
> expression E1, E2, COUNT, x1, x2, x3;
> typedef u8;
> typedef __u8;
> type t = {u8,__u8,char,unsigned char};
> identifier alloc = {vmalloc,vzalloc};
> fresh identifier realloc = script:ocaml(alloc) { rename alloc };
> @@
>
> (
> alloc(x1*x2*x3)
> |
> alloc(C1 * C2)
> |
> alloc((sizeof(t)) * (COUNT), ...)
> |
> - alloc((e1) * (e2))
> + realloc(e1, e2)
> |
> - alloc((e1) * (COUNT))
> + realloc(COUNT, e1)
> |
> - alloc((E1) * (E2))
> + realloc(E1, E2)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> ---
Thanks, applied to drm-misc-next.
Noralf.
> v2: Use vmalloc_array and vcalloc instead of array_size.
> This also leaves a multiplication of a constant by a sizeof
> as is. Two patches are thus dropped from the series.
>
> drivers/gpu/drm/gud/gud_pipe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
> --- a/drivers/gpu/drm/gud/gud_pipe.c
> +++ b/drivers/gpu/drm/gud/gud_pipe.c
> @@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu
> mutex_lock(&gdrm->damage_lock);
>
> if (!gdrm->shadow_buf) {
> - gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height);
> + gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height);
> if (!gdrm->shadow_buf) {
> mutex_unlock(&gdrm->damage_lock);
> return -ENOMEM;
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 06/24] dma-buf: system_heap: use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
@ 2023-06-27 14:43 ` Julia Lawall
2023-06-27 18:52 ` John Stultz
2023-06-27 14:43 ` [PATCH v2 15/24] habanalabs: " Julia Lawall
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2023-06-27 14:43 UTC (permalink / raw)
To: Sumit Semwal
Cc: Benjamin Gaignard, keescook, kernel-janitors, linux-kernel,
Liam Mark, Christian König, linaro-mm-sig, John Stultz,
christophe.jaillet, dri-devel, kuba, Laura Abbott, linux-media
Use vmalloc_array and vcalloc to protect against
multiplication overflows.
The changes were done using the following Coccinelle
semantic patch:
// <smpl>
@initialize:ocaml@
@@
let rename alloc =
match alloc with
"vmalloc" -> "vmalloc_array"
| "vzalloc" -> "vcalloc"
| _ -> failwith "unknown"
@@
size_t e1,e2;
constant C1, C2;
expression E1, E2, COUNT, x1, x2, x3;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@
(
alloc(x1*x2*x3)
|
alloc(C1 * C2)
|
alloc((sizeof(t)) * (COUNT), ...)
|
- alloc((e1) * (e2))
+ realloc(e1, e2)
|
- alloc((e1) * (COUNT))
+ realloc(COUNT, e1)
|
- alloc((E1) * (E2))
+ realloc(E1, E2)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is. Two patches are thus dropped from the series.
drivers/dma-buf/heaps/system_heap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff -u -p a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -221,7 +221,7 @@ static void *system_heap_do_vmap(struct
{
struct sg_table *table = &buffer->sg_table;
int npages = PAGE_ALIGN(buffer->len) / PAGE_SIZE;
- struct page **pages = vmalloc(sizeof(struct page *) * npages);
+ struct page **pages = vmalloc_array(npages, sizeof(struct page *));
struct page **tmp = pages;
struct sg_page_iter piter;
void *vaddr;
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 06/24] dma-buf: system_heap: use vmalloc_array and vcalloc
2023-06-27 14:43 ` [PATCH v2 06/24] dma-buf: system_heap: " Julia Lawall
@ 2023-06-27 18:52 ` John Stultz
0 siblings, 0 replies; 12+ messages in thread
From: John Stultz @ 2023-06-27 18:52 UTC (permalink / raw)
To: Julia Lawall
Cc: Benjamin Gaignard, keescook, Christian König,
kernel-janitors, linux-kernel, Liam Mark, linaro-mm-sig,
christophe.jaillet, dri-devel, kuba, Laura Abbott, Sumit Semwal,
linux-media
On Tue, Jun 27, 2023 at 7:44 AM Julia Lawall <Julia.Lawall@inria.fr> wrote:
>
> Use vmalloc_array and vcalloc to protect against
> multiplication overflows.
>
> The changes were done using the following Coccinelle
> semantic patch:
>
> // <smpl>
> @initialize:ocaml@
> @@
>
> let rename alloc =
> match alloc with
> "vmalloc" -> "vmalloc_array"
> | "vzalloc" -> "vcalloc"
> | _ -> failwith "unknown"
>
> @@
> size_t e1,e2;
> constant C1, C2;
> expression E1, E2, COUNT, x1, x2, x3;
> typedef u8;
> typedef __u8;
> type t = {u8,__u8,char,unsigned char};
> identifier alloc = {vmalloc,vzalloc};
> fresh identifier realloc = script:ocaml(alloc) { rename alloc };
> @@
>
> (
> alloc(x1*x2*x3)
> |
> alloc(C1 * C2)
> |
> alloc((sizeof(t)) * (COUNT), ...)
> |
> - alloc((e1) * (e2))
> + realloc(e1, e2)
> |
> - alloc((e1) * (COUNT))
> + realloc(COUNT, e1)
> |
> - alloc((E1) * (E2))
> + realloc(E1, E2)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> ---
> v2: Use vmalloc_array and vcalloc instead of array_size.
> This also leaves a multiplication of a constant by a sizeof
> as is. Two patches are thus dropped from the series.
>
> drivers/dma-buf/heaps/system_heap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -221,7 +221,7 @@ static void *system_heap_do_vmap(struct
> {
> struct sg_table *table = &buffer->sg_table;
> int npages = PAGE_ALIGN(buffer->len) / PAGE_SIZE;
> - struct page **pages = vmalloc(sizeof(struct page *) * npages);
> + struct page **pages = vmalloc_array(npages, sizeof(struct page *));
> struct page **tmp = pages;
> struct sg_page_iter piter;
> void *vaddr;
Seems reasonable. Thanks for sending this out!
Acked-by: John Stultz <jstultz@google.com>
thanks
-john
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 15/24] habanalabs: use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 06/24] dma-buf: system_heap: " Julia Lawall
@ 2023-06-27 14:43 ` Julia Lawall
2023-07-02 8:01 ` Oded Gabbay
2023-06-27 14:43 ` [PATCH v2 16/24] drm/i915/gvt: " Julia Lawall
` (3 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2023-06-27 14:43 UTC (permalink / raw)
To: Oded Gabbay
Cc: keescook, kernel-janitors, linux-kernel, dri-devel,
christophe.jaillet, kuba
Use vmalloc_array and vcalloc to protect against
multiplication overflows.
The changes were done using the following Coccinelle
semantic patch:
// <smpl>
@initialize:ocaml@
@@
let rename alloc =
match alloc with
"vmalloc" -> "vmalloc_array"
| "vzalloc" -> "vcalloc"
| _ -> failwith "unknown"
@@
size_t e1,e2;
constant C1, C2;
expression E1, E2, COUNT, x1, x2, x3;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@
(
alloc(x1*x2*x3)
|
alloc(C1 * C2)
|
alloc((sizeof(t)) * (COUNT), ...)
|
- alloc((e1) * (e2))
+ realloc(e1, e2)
|
- alloc((e1) * (COUNT))
+ realloc(COUNT, e1)
|
- alloc((E1) * (E2))
+ realloc(E1, E2)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is. Two patches are thus dropped from the series.
drivers/accel/habanalabs/common/device.c | 3 ++-
drivers/accel/habanalabs/common/state_dump.c | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff -u -p a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -2594,7 +2594,8 @@ static void hl_capture_user_mappings(str
*/
vfree(pgf_info->user_mappings);
pgf_info->user_mappings =
- vzalloc(pgf_info->num_of_user_mappings * sizeof(struct hl_user_mapping));
+ vcalloc(pgf_info->num_of_user_mappings,
+ sizeof(struct hl_user_mapping));
if (!pgf_info->user_mappings) {
pgf_info->num_of_user_mappings = 0;
goto finish;
diff -u -p a/drivers/accel/habanalabs/common/state_dump.c b/drivers/accel/habanalabs/common/state_dump.c
--- a/drivers/accel/habanalabs/common/state_dump.c
+++ b/drivers/accel/habanalabs/common/state_dump.c
@@ -272,7 +272,8 @@ static u32 *hl_state_dump_read_sync_obje
base_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] +
sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index;
- sync_objects = vmalloc(sds->props[SP_SYNC_OBJ_AMOUNT] * sizeof(u32));
+ sync_objects = vmalloc_array(sds->props[SP_SYNC_OBJ_AMOUNT],
+ sizeof(u32));
if (!sync_objects)
return NULL;
@@ -453,8 +454,8 @@ hl_state_dump_alloc_read_sm_block_monito
s64 base_addr; /* Base addr can be negative */
int i;
- monitors = vmalloc(sds->props[SP_MONITORS_AMOUNT] *
- sizeof(struct hl_mon_state_dump));
+ monitors = vmalloc_array(sds->props[SP_MONITORS_AMOUNT],
+ sizeof(struct hl_mon_state_dump));
if (!monitors)
return NULL;
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 15/24] habanalabs: use vmalloc_array and vcalloc
2023-06-27 14:43 ` [PATCH v2 15/24] habanalabs: " Julia Lawall
@ 2023-07-02 8:01 ` Oded Gabbay
0 siblings, 0 replies; 12+ messages in thread
From: Oded Gabbay @ 2023-07-02 8:01 UTC (permalink / raw)
To: Julia Lawall
Cc: keescook, kernel-janitors, linux-kernel, dri-devel,
christophe.jaillet, kuba
On Tue, Jun 27, 2023 at 5:44 PM Julia Lawall <Julia.Lawall@inria.fr> wrote:
>
> Use vmalloc_array and vcalloc to protect against
> multiplication overflows.
>
> The changes were done using the following Coccinelle
> semantic patch:
>
> // <smpl>
> @initialize:ocaml@
> @@
>
> let rename alloc =
> match alloc with
> "vmalloc" -> "vmalloc_array"
> | "vzalloc" -> "vcalloc"
> | _ -> failwith "unknown"
>
> @@
> size_t e1,e2;
> constant C1, C2;
> expression E1, E2, COUNT, x1, x2, x3;
> typedef u8;
> typedef __u8;
> type t = {u8,__u8,char,unsigned char};
> identifier alloc = {vmalloc,vzalloc};
> fresh identifier realloc = script:ocaml(alloc) { rename alloc };
> @@
>
> (
> alloc(x1*x2*x3)
> |
> alloc(C1 * C2)
> |
> alloc((sizeof(t)) * (COUNT), ...)
> |
> - alloc((e1) * (e2))
> + realloc(e1, e2)
> |
> - alloc((e1) * (COUNT))
> + realloc(COUNT, e1)
> |
> - alloc((E1) * (E2))
> + realloc(E1, E2)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> ---
> v2: Use vmalloc_array and vcalloc instead of array_size.
> This also leaves a multiplication of a constant by a sizeof
> as is. Two patches are thus dropped from the series.
>
> drivers/accel/habanalabs/common/device.c | 3 ++-
> drivers/accel/habanalabs/common/state_dump.c | 7 ++++---
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff -u -p a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c
> --- a/drivers/accel/habanalabs/common/device.c
> +++ b/drivers/accel/habanalabs/common/device.c
> @@ -2594,7 +2594,8 @@ static void hl_capture_user_mappings(str
> */
> vfree(pgf_info->user_mappings);
> pgf_info->user_mappings =
> - vzalloc(pgf_info->num_of_user_mappings * sizeof(struct hl_user_mapping));
> + vcalloc(pgf_info->num_of_user_mappings,
> + sizeof(struct hl_user_mapping));
> if (!pgf_info->user_mappings) {
> pgf_info->num_of_user_mappings = 0;
> goto finish;
> diff -u -p a/drivers/accel/habanalabs/common/state_dump.c b/drivers/accel/habanalabs/common/state_dump.c
> --- a/drivers/accel/habanalabs/common/state_dump.c
> +++ b/drivers/accel/habanalabs/common/state_dump.c
> @@ -272,7 +272,8 @@ static u32 *hl_state_dump_read_sync_obje
> base_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] +
> sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index;
>
> - sync_objects = vmalloc(sds->props[SP_SYNC_OBJ_AMOUNT] * sizeof(u32));
> + sync_objects = vmalloc_array(sds->props[SP_SYNC_OBJ_AMOUNT],
> + sizeof(u32));
> if (!sync_objects)
> return NULL;
>
> @@ -453,8 +454,8 @@ hl_state_dump_alloc_read_sm_block_monito
> s64 base_addr; /* Base addr can be negative */
> int i;
>
> - monitors = vmalloc(sds->props[SP_MONITORS_AMOUNT] *
> - sizeof(struct hl_mon_state_dump));
> + monitors = vmalloc_array(sds->props[SP_MONITORS_AMOUNT],
> + sizeof(struct hl_mon_state_dump));
> if (!monitors)
> return NULL;
>
>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 16/24] drm/i915/gvt: use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
` (2 preceding siblings ...)
2023-06-27 14:43 ` [PATCH v2 15/24] habanalabs: " Julia Lawall
@ 2023-06-27 14:43 ` Julia Lawall
2023-06-27 16:40 ` [PATCH v2 00/24] " patchwork-bot+netdevbpf
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Julia Lawall @ 2023-06-27 14:43 UTC (permalink / raw)
To: Zhenyu Wang
Cc: Tvrtko Ursulin, keescook, intel-gvt-dev, intel-gfx,
kernel-janitors, linux-kernel, christophe.jaillet, dri-devel,
Rodrigo Vivi, kuba, Zhi Wang
Use vmalloc_array and vcalloc to protect against
multiplication overflows.
The changes were done using the following Coccinelle
semantic patch:
// <smpl>
@initialize:ocaml@
@@
let rename alloc =
match alloc with
"vmalloc" -> "vmalloc_array"
| "vzalloc" -> "vcalloc"
| _ -> failwith "unknown"
@@
size_t e1,e2;
constant C1, C2;
expression E1, E2, COUNT, x1, x2, x3;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@
(
alloc(x1*x2*x3)
|
alloc(C1 * C2)
|
alloc((sizeof(t)) * (COUNT), ...)
|
- alloc((e1) * (e2))
+ realloc(e1, e2)
|
- alloc((e1) * (COUNT))
+ realloc(COUNT, e1)
|
- alloc((E1) * (E2))
+ realloc(E1, E2)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is. Two patches are thus dropped from the series.
drivers/gpu/drm/i915/gvt/gtt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff -u -p a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -1969,14 +1969,16 @@ static struct intel_vgpu_mm *intel_vgpu_
return ERR_PTR(-ENOMEM);
}
- mm->ggtt_mm.host_ggtt_aperture = vzalloc((vgpu_aperture_sz(vgpu) >> PAGE_SHIFT) * sizeof(u64));
+ mm->ggtt_mm.host_ggtt_aperture = vcalloc(vgpu_aperture_sz(vgpu) >> PAGE_SHIFT,
+ sizeof(u64));
if (!mm->ggtt_mm.host_ggtt_aperture) {
vfree(mm->ggtt_mm.virtual_ggtt);
vgpu_free_mm(mm);
return ERR_PTR(-ENOMEM);
}
- mm->ggtt_mm.host_ggtt_hidden = vzalloc((vgpu_hidden_sz(vgpu) >> PAGE_SHIFT) * sizeof(u64));
+ mm->ggtt_mm.host_ggtt_hidden = vcalloc(vgpu_hidden_sz(vgpu) >> PAGE_SHIFT,
+ sizeof(u64));
if (!mm->ggtt_mm.host_ggtt_hidden) {
vfree(mm->ggtt_mm.host_ggtt_aperture);
vfree(mm->ggtt_mm.virtual_ggtt);
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 00/24] use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
` (3 preceding siblings ...)
2023-06-27 14:43 ` [PATCH v2 16/24] drm/i915/gvt: " Julia Lawall
@ 2023-06-27 16:40 ` patchwork-bot+netdevbpf
2023-07-06 1:35 ` Martin K. Petersen
2023-07-11 16:31 ` (subset) " Martin K. Petersen
6 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-27 16:40 UTC (permalink / raw)
To: Julia Lawall
Cc: linux-hyperv, dave.hansen, kernel-janitors, dri-devel,
virtualization, jstultz, hpa, linux-sgx, xuanzhuo,
benjamin.gaignard, linux-scsi, linux-rdma, kasan-dev, iommu, kuba,
labbott, linux-media, keescook, linux-arm-msm, intel-gfx,
linaro-mm-sig, vdumpa, shailend, christophe.jaillet, linux-tegra,
intel-gvt-dev, dvyukov, andreyknvl, netdev, linux-kernel, lmark,
mhi, robin.murphy, linux-btrfs
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 27 Jun 2023 16:43:15 +0200 you wrote:
> The functions vmalloc_array and vcalloc were introduced in
>
> commit a8749a35c399 ("mm: vmalloc: introduce array allocation functions")
>
> but are not used much yet. This series introduces uses of
> these functions, to protect against multiplication overflows.
>
> [...]
Here is the summary with links:
- [v2,02/24] octeon_ep: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/32d462a5c3e5
- [v2,04/24] gve: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/a13de901e8d5
- [v2,09/24] pds_core: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/906a76cc7645
- [v2,11/24] ionic: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/f712c8297e0a
- [v2,18/24] net: enetc: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/fa87c54693ae
- [v2,22/24] net: mana: use vmalloc_array and vcalloc
https://git.kernel.org/netdev/net-next/c/e9c74f8b8a31
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2 00/24] use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
` (4 preceding siblings ...)
2023-06-27 16:40 ` [PATCH v2 00/24] " patchwork-bot+netdevbpf
@ 2023-07-06 1:35 ` Martin K. Petersen
2023-07-11 16:31 ` (subset) " Martin K. Petersen
6 siblings, 0 replies; 12+ messages in thread
From: Martin K. Petersen @ 2023-07-06 1:35 UTC (permalink / raw)
To: Julia Lawall
Cc: linux-hyperv, Dave Hansen, kernel-janitors, dri-devel,
virtualization, John Stultz, H. Peter Anvin, linux-sgx, Xuan Zhuo,
Benjamin Gaignard, linux-scsi, linux-rdma, kasan-dev, iommu, kuba,
Laura Abbott, linux-media, keescook, linux-arm-msm, intel-gfx,
linaro-mm-sig, Krishna Reddy, Shailend Chand, christophe.jaillet,
linux-tegra, intel-gvt-dev, Dmitry Vyukov, Andrey Konovalov,
netdev, linux-kernel, Liam Mark, mhi, Robin Murphy, linux-btrfs
Julia,
> The functions vmalloc_array and vcalloc were introduced in
>
> commit a8749a35c399 ("mm: vmalloc: introduce array allocation functions")
>
> but are not used much yet. This series introduces uses of
> these functions, to protect against multiplication overflows.
Applied #7 and #24 to 6.5/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: (subset) [PATCH v2 00/24] use vmalloc_array and vcalloc
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
` (5 preceding siblings ...)
2023-07-06 1:35 ` Martin K. Petersen
@ 2023-07-11 16:31 ` Martin K. Petersen
6 siblings, 0 replies; 12+ messages in thread
From: Martin K. Petersen @ 2023-07-11 16:31 UTC (permalink / raw)
To: linux-hyperv, Julia Lawall
Cc: Dave Hansen, kernel-janitors, dri-devel, virtualization,
John Stultz, H. Peter Anvin, linux-sgx, Xuan Zhuo,
Benjamin Gaignard, linux-scsi, linux-rdma, kasan-dev, iommu, kuba,
Laura Abbott, linux-media, keescook, linux-arm-msm, intel-gfx,
linaro-mm-sig, Krishna Reddy, Shailend Chand, christophe.jaillet,
linux-tegra, intel-gvt-dev, Dmitry Vyukov, Andrey Konovalov,
Martin K . Petersen, netdev, linux-kernel, Liam Mark, mhi,
Robin Murphy, linux-btrfs
On Tue, 27 Jun 2023 16:43:15 +0200, Julia Lawall wrote:
> The functions vmalloc_array and vcalloc were introduced in
>
> commit a8749a35c399 ("mm: vmalloc: introduce array allocation functions")
>
> but are not used much yet. This series introduces uses of
> these functions, to protect against multiplication overflows.
>
> [...]
Applied to 6.5/scsi-fixes, thanks!
[07/24] scsi: fnic: use vmalloc_array and vcalloc
https://git.kernel.org/mkp/scsi/c/b34c7dcaf311
[24/24] scsi: qla2xxx: use vmalloc_array and vcalloc
https://git.kernel.org/mkp/scsi/c/04d91b783acf
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 12+ messages in thread