Commit Graph

28501 Commits

Author SHA1 Message Date
Kees Cook
3592eba0e6 treewide: Use array_size() in vzalloc()
The vzalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:

        vzalloc(a * b)

with:
        vzalloc(array_size(a, b))

as well as handling cases of:

        vzalloc(a * b * c)

with:

        vzalloc(array3_size(a, b, c))

This does, however, attempt to ignore constant size factors like:

        vzalloc(4 * 1024)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  vzalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  vzalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  vzalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  vzalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
  vzalloc(
-	sizeof(TYPE) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * COUNT_ID
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(THING) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * COUNT_ID
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

  vzalloc(
-	SIZE * COUNT
+	array_size(COUNT, SIZE)
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  vzalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vzalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vzalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  vzalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  vzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  vzalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  vzalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  vzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  vzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  vzalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vzalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  vzalloc(C1 * C2 * C3, ...)
|
  vzalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@

(
  vzalloc(C1 * C2, ...)
|
  vzalloc(
-	E1 * E2
+	array_size(E1, E2)
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:54 +05:30
Kees Cook
f0a8bd5618 treewide: Use array_size() in vmalloc()
The vmalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:

        vmalloc(a * b)

with:
        vmalloc(array_size(a, b))

as well as handling cases of:

        vmalloc(a * b * c)

with:

        vmalloc(array3_size(a, b, c))

This does, however, attempt to ignore constant size factors like:

        vmalloc(4 * 1024)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  vmalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  vmalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  vmalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  vmalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
  vmalloc(
-	sizeof(TYPE) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT_ID
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT_ID
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

  vmalloc(
-	SIZE * COUNT
+	array_size(COUNT, SIZE)
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  vmalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  vmalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  vmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  vmalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  vmalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  vmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  vmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  vmalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  vmalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  vmalloc(C1 * C2 * C3, ...)
|
  vmalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@

(
  vmalloc(C1 * C2, ...)
|
  vmalloc(
-	E1 * E2
+	array_size(E1, E2)
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:54 +05:30
Kees Cook
99d27d6fb6 treewide: kzalloc_node() -> kcalloc_node()
The kzalloc_node() function has a 2-factor argument form, kcalloc_node(). This
patch replaces cases of:

        kzalloc_node(a * b, gfp, node)

with:
        kcalloc_node(a * b, gfp, node)

as well as handling cases of:

        kzalloc_node(a * b * c, gfp, node)

with:

        kzalloc_node(array3_size(a, b, c), gfp, node)

as it's slightly less ugly than:

        kcalloc_node(array_size(a, b), c, gfp, node)

This does, however, attempt to ignore constant size factors like:

        kzalloc_node(4 * 1024, gfp, node)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kzalloc_node(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kzalloc_node(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kzalloc_node(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kzalloc_node(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kzalloc_node
+ kcalloc_node
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kzalloc_node(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc_node(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc_node(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc_node(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc_node(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kzalloc_node(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc_node(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc_node(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kzalloc_node(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kzalloc_node(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc_node(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kzalloc_node(C1 * C2 * C3, ...)
|
  kzalloc_node(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc_node(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc_node(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc_node(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kzalloc_node(sizeof(THING) * C2, ...)
|
  kzalloc_node(sizeof(TYPE) * C2, ...)
|
  kzalloc_node(C1 * C2 * C3, ...)
|
  kzalloc_node(C1 * C2, ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kzalloc_node
+ kcalloc_node
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:53 +05:30
Kees Cook
41b77821cf treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

        kzalloc(a * b, gfp)

with:
        kcalloc(a * b, gfp)

as well as handling cases of:

        kzalloc(a * b * c, gfp)

with:

        kzalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kzalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kzalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kzalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kzalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kzalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kzalloc
+ kcalloc
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kzalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kzalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kzalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kzalloc(sizeof(THING) * C2, ...)
|
  kzalloc(sizeof(TYPE) * C2, ...)
|
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:52 +05:30
Kees Cook
88739c4879 treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:

        kmalloc(a * b, gfp)

with:
        kmalloc_array(a * b, gfp)

as well as handling cases of:

        kmalloc(a * b * c, gfp)

with:

        kmalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kmalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kmalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kmalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kmalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kmalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kmalloc
+ kmalloc_array
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kmalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kmalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kmalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kmalloc(sizeof(THING) * C2, ...)
|
  kmalloc(sizeof(TYPE) * C2, ...)
|
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:52 +05:30
Kees Cook
0f37f111de treewide: Use struct_size() for kmalloc()-family
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:

// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
//                      sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-17 18:55:51 +05:30
Sultan Alsawaf
8da7ea0182 kernel: Warn when an IRQ's affinity notifier gets overwritten
An IRQ affinity notifier getting overwritten can point to some annoying
issues which need to be resolved, like multiple pm_qos objects being
registered to the same IRQ. Print out a warning when this happens to aid
debugging.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-16 23:24:49 +05:30
Sultan Alsawaf
99e0da6885 kernel: Only set one CPU in the default IRQ affinity mask
On ARM, IRQs are executed on the first CPU inside the affinity mask, so
setting an affinity mask with more than one CPU set is deceptive and
causes issues with pm_qos. To fix this, only set the CPU0 bit inside the
affinity mask, since that's where IRQs will run by default.

This is a follow-up to "kernel: Don't allow IRQ affinity masks to have
more than one CPU".

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-16 23:24:48 +05:30
celtare21
2c193c9897 Revert "genirq: Add default affinity mask command line option"
This reverts commit fbf198030e.

Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-16 23:24:47 +05:30
celtare21
3d69d24640 Revert "irq/core: Fix boot crash when the irqaffinity= boot parameter is passed on CPUMASK_OFFSTACK=y kernels(v1)"
This reverts commit 07a1c2d113.

Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-16 23:24:47 +05:30
UtsavBalar1231
5a63f7f513 Merge remote-tracking branch 'origin/q' into auto-kernel
* origin/q:
  qcacmn: Fix suspicious string concatenation warning in fwlog
  qcacld-3.0: Fix regulatory domain country names
  selinux: randomize layout of key structures
  selinux: remove set but not used variable 'sidtab'
  selinux: ensure the policy has been loaded before reading the sidtab stats
  selinux: fix sidtab string cache locking
  BACKPORT: selinux: cache the SID -> context string translation
  rcu: Make kfree_rcu() ignore NULL pointers
  selinux: remove useless assignments
  selinux: log invalid contexts in AVCs
  BACKPORT: selinux: convert to kvmalloc
  mm: Introduce kvcalloc()
  msm: camera: reqmgr: Stop slot reset on buf done
  msm: mhi_dev: Fix memory leak
  msm: camera: csiphy: Update phy settings for atoll
  msm: camera: core: Change return type
  msm: camera: reqmgr: Skip apply for initial sync req on slave link
  msm: camera: reqmgr: increase the rd idx if no lower pd device
  msm: camera: reqmgr: reset slots after deactivating session
  jpeg: Add DMA driver implementation
  ARM: dts: msm: Include qcs610 changes for qcs410 also
  BACKPORT: loop: Fix wrong masking of status flags
  BACKPORT: loop: Add LOOP_CONFIGURE ioctl
  BACKPORT: loop: Clean up LOOP_SET_STATUS lo_flags handling
  BACKPORT: loop: Rework lo_ioctl() __user argument casting
  BACKPORT: loop: Move loop_set_status_from_info() and friends up
  BACKPORT: loop: Factor out configuring loop from status
  BACKPORT: loop: Remove figure_loop_size()
  BACKPORT: loop: Refactor loop_set_status() size calculation
  BACKPORT: loop: Factor out setting loop device size
  BACKPORT: loop: Remove sector_t truncation checks
  BACKPORT: loop: Call loop_config_discard() only after new config is applied
  qcacld-3.0: Flush pmksa cache for SAP when SAP stop
  Linux 4.14.193
  ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()
  ext4: fix direct I/O read error
  random32: move the pseudo-random 32-bit definitions to prandom.h
  random32: remove net_rand_state from the latent entropy gcc plugin
  random: fix circular include dependency on arm64 after addition of percpu.h
  ARM: percpu.h: fix build error
  random32: update the net random state on interrupt and activity
  Revert "scsi: libsas: direct call probe and destruct"
  Revert "clk: qcom: rcg2: Don't crash if our parent can't be found; return an error"
  Reverting crypto patches
  msm: ipa3: put ecm default as vlan in auto config
  ARM: dts: sa2150p: delete wlan related nodes for sa2150p target
  ARM: dts: sa2150p: override certain memory regions for sa2150p-nand
  serial: msm_geni_serial: Fix DMA RX FSM reset sequence
  defconfig: Disable the arm cpuidle support for sdm429
  defconfig: msm: Add config fragment for DEBUG_FS disablement
  scripts: Consider env variables while running 'make'
  Documentation: devicetree: net: Add EMAC configuration options
  drivers: thermal: call TSENS re-init only when register is ready to update
  drivers: cpuidle: lpm-levels: check for valid LPM stats
  msm: camera: cci: Fix incorrect use of cci config ioctl
  power: smb1390: Fix taper condition for VPH configuration
  msm: ipa3: Fix to unmap sgt pages with correct size
  ARM: dts: sa515m: enable ssr and wake up sideband support
  ARM: dts: sa515m: correct sideband wakeup gpio numbers
  uapi: sound: add TTP pass through run mode command
  ARM: dts: msm: enable fuel gauge driver
  ARM: dts: msm: Enable default thermal zones and cooling devices for sdm429
  defconfig: sa2150p: Remove unwanted debug configs
  ARM: dts: msm: Add correct board name for SDX55 MTP Telematics AU DSDA
  ARM: dts: msm: Add virtual display connector for sa8155
  ARM: dts: msm: Add virtual display connector for sa6155
  ARM: dts: msm: Enable slimbus slave for SDMw429
  usb: gadget: f_ipc: Wait for req completion only when suspended
  Revert "ARM: dts: msm: add display related dt nodes on QCS410 device"
  clk: qcom: npucc: Update NPU Q6 frequency for ATOLL
  Revert "drm/msm/sde: use atomic counter for pending frame done"
  Revert "drm/msm/sde: support posted frame trigger for cmd mode"
  Revert "drm/msm/sde: delay reset frame by a frame for posted trigger"
  Revert "drm/msm/sde: add connector property for frame trigger mode"
  ARM: dts: msm: Configure "qcom,sync-dly" to 800us for SDM660
  backlight: qcom-wled: Add "qcom,sync-dly" device tree property
  Revert "drm/msm/sde: avoid frame done event during autorefresh"
  Revert "drm/msm/sde: trigger frame done if ctl is idle"
  Revert "disp: msm: sde: use wr_ptr interrupt instead of ctl_start"
  Revert "disp: msm: sde: reset ctl during wr_ptr_irq timeout"
  Revert "disp: msm: sde: fix release fence signaling in error cases"
  Revert "disp: msm: sde: wait for specific pp_done instead of zero"
  Revert "disp: msm: sde: fix handling the missing pp-done interrupt cases"
  Revert "disp: msm: sde: avoid encoder power-collapse with pending frames"
  Revert "disp: msm: sde: handle another case for lost pp-done interrupt"
  Revert "disp: msm: sde: signal retire fence in wr_ptr timeout"
  Revert "disp: msm: sde: avoid multiple frame-done encoder events"
  Revert "drm/msm/dsi-staging: update dsi clock calculations"
  Revert "drm/msm/dsi-staging: update frame transfer time calculations"
  Revert "disp: msm: dsi: update dsi pclk in panel mode settings"
  Revert "dt-bindings: Add frame threshold property for dsi controller"
  Revert "ARM: dts: msm: update frame threshold time for atoll"
  Revert "drm/msm/sde: initialize sde_encoder_wait_info before usage"
  Revert "drm/msm/sde: avoid frame_done event trigger for idle scenario"
  Revert "drm/msm/sde: trigger single frame_done evt for vid encoder"
  coresight: cti: Add sys interface to show max trigger number
  ARM: dts: msm: Add memshare for sdm429
  rpmsg: qcom_glink_bgcom: Clean up the channels after SSR
  defconfig: Enable FS related configs
  defconfig: Disable CRYPTO_MD4 config
  defconfig: For support api_30 kernel changes
  ARM: dts: qcom: add video device tree entry for sdm429w
  msm: mhi_dev: allocate high priority Workqueue for mhi_sm_wq
  drivers: soc: rename block device nodes
  clk: qcom: mdss: Add check to read the gdsc status
  drm/msm/sde: trigger single frame_done evt for vid encoder
  drm/msm/sde: avoid frame_done event trigger for idle scenario
  drm/msm/sde: initialize sde_encoder_wait_info before usage
  Reverting incremental fs changes
  ARM: dts: qcom: Add system secure ion heap for Quin GVM
  drm/msm/dsi-staging: fix t_clk_pre in high dsi clock use case
  dt-bindings: add clock_pre extend enable panel property
  fw-api: CL 11046353 - update fw common interface files
  Release 5.2.03.29I
  fw-api: CL 11039524 - update fw common interface files
  fw-api: CL 11034593 - update fw common interface files
  fw-api: CL 11025894 - update fw common interface files
  fw-api: CL 11024688 - update fw common interface files
  fw-api: CL 11019489 - update fw common interface files
  fw-api: CL 11006718 - update fw common interface files
  fw-api: CL 10992505 - update fw common interface files
  fw-api: CL 10972934 - update fw common interface files
  fw-api: CL 10966184 - update fw common interface files
  qcacmn: Send vdev param NAN_CONFIG_FEATURES after creating vdev
  qcacld-3.0: Send vdev param NAN_CONFIG_FEATURES after creating vdev
  Release 5.2.03.29H
  qcacld-3.0: Limit the number of times get_tx_power can come
  Release 5.2.03.29G
  qcacld-3.0: Fix Mlme info updating in connected BSS in scan
  Release 5.2.03.29F
  qcacld-3.0: Fix pm_qos update logic
  qcacld-3.0: CPU mask not set for affine cores on init
  Release 5.2.03.29E
  qcacld-3.0: Update pm_qos request only if vote or tx or rx level changes
  qcacmn: Define QDF API for cpumask abstraction
  qcacmn: Add QDF API to set thread cpu mask
  qcacmn: Add vdev param to configure NAN feature bitmap to firmware
  Release 5.2.03.29D
  qcacld-3.0: Ini bitmap to enable/disable a particular NAN feature
  Release 5.2.03.29C
  qcacmn: Invoke correct api to convert channel to frequency
  qcacmn: Make freq to chan and vice versa conversion more generic
  qcacld-3.0: Allocate required memory for skb and radiotap
  qcacmn: Fix OOB issue in wlan_parse_rsn_ie
  Release 5.2.03.29B
  qcacld-3.0: Change the RX thread policy for qcs40x soc
  ANDROID: cuttlefish_defconfig: Drop built-in cmdline
  Release 5.2.03.29A
  qcacld-3.0: Change the policy & priority of RX thread
  Release 5.2.03.29
  ARM: dts: msm: Disable GPU mempools for QCS610 IoT
  qcacld-3.0: Add handler for WMI_VDEV_BCN_LATENCY_EVENTID
  Release 5.2.03.28Z
  qcacld-3.0: Remove unnecessary clone of skb
  fw-api: CL 10917877 - update fw common interface files
  fw-api: CL 10899787 - update fw common interface files
  fw-api: CL 10894153 - update fw common interface files
  fw-api: CL 10878097 - update fw common interface files
  fw-api: CL 10874626 - update fw common interface files
  fw-api: CL 10864082 - update fw common interface files
  fw-api: CL 10859209 - update fw common interface files
  qcacmn: Add support for WMI_VDEV_BCN_LATENCY event
  qcacmn: fix format specifier in qdf_dpt_dump_stats_debugfs
  Release 5.2.03.28Y
  qcacld-3.0: initialize peer hang_data in recovery_notifier_cb
  Release 5.2.03.28X
  qcacld-3.0: Add reference when access vdev
  Release 5.2.03.28W
  qcacld-3.0: Fix assert in sme_store_nss_chains_cfg
  ARM: dts: msm: update frame threshold time for atoll
  dt-bindings: Add frame threshold property for dsi controller
  disp: msm: dsi: update dsi pclk in panel mode settings
  drm/msm/dsi-staging: update frame transfer time calculations
  drm/msm/dsi-staging: update dsi clock calculations
  disp: msm: sde: avoid multiple frame-done encoder events
  disp: msm: sde: signal retire fence in wr_ptr timeout
  disp: msm: sde: handle another case for lost pp-done interrupt
  disp: msm: sde: avoid encoder power-collapse with pending frames
  disp: msm: sde: fix handling the missing pp-done interrupt cases
  disp: msm: sde: wait for specific pp_done instead of zero
  disp: msm: sde: fix release fence signaling in error cases
  disp: msm: sde: reset ctl during wr_ptr_irq timeout
  disp: msm: sde: use wr_ptr interrupt instead of ctl_start
  drm/msm/sde: trigger frame done if ctl is idle
  drm/msm/sde: avoid frame done event during autorefresh
  drm/msm/sde: add connector property for frame trigger mode
  drm/msm/sde: delay reset frame by a frame for posted trigger
  drm/msm/sde: support posted frame trigger for cmd mode
  drm/msm/sde: use atomic counter for pending frame done
  ANDROID: arm64: vdso: wrap -n in ld-option
  BACKPORT: arm64: vdso: Explicitly add build-id option
  BACKPORT: arm64: vdso: use $(LD) instead of $(CC) to link VDSO
  ANDROID: cuttlefish defconfig - enable mount/net/uts namespaces.
  ANDROID: net: bpf: permit redirect from ingress L3 to egress L2 devices at near max mtu
  UPSTREAM: mm/page_io.c: annotate refault stalls from swap_readpage
  ANDROID: cuttlefish_defconfig: Fix dm-verity related options
  BACKPORT: loop: Add LOOP_SET_BLOCK_SIZE in compat ioctl
  BACKPORT: loop: change queue block size to match when using DIO
  ANDROID: cuttlefish_defconfig: Minimally enable EFI
  UPSTREAM: loop: Only freeze block queue when needed.
  UPSTREAM: loop: Only change blocksize when needed.
  UPSTREAM: ipv6: ndisc: add support for 'PREF64' dns64 prefix identifier
  ANDROID: dm-bow: Fix free_show value is incorrect
  UPSTREAM: bpf: Explicitly memset some bpf info structures declared on the stack
  UPSTREAM: bpf: Explicitly memset the bpf_attr structure
  UPSTREAM: binder: fix incorrect calculation for num_valid
  UPSTREAM: sched/psi: Fix OOB write when writing 0 bytes to PSI files
  UPSTREAM: psi: Fix a division error in psi poll()
  UPSTREAM: sched/psi: Fix sampling error and rare div0 crashes with cgroups and high uptime
  UPSTREAM: sched/psi: Correct overly pessimistic size calculation
  ANDROID: net: bpf: Allow TC programs to call BPF_FUNC_skb_change_head

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>

Conflicts:
	arch/arm64/kernel/traps.c
	drivers/base/arch_topology.c
	drivers/base/power/wakeup.c
	drivers/irqchip/irq-gic-v3.c
	drivers/scsi/sd.c
	drivers/soc/qcom/Makefile
	drivers/tty/serial/msm_geni_serial.c
2020-08-16 22:54:04 +05:30
UtsavBalar1231
3de33b8d44 Merge remote-tracking branch 'aosp/android-4.14-stable' into q
* aosp/android-4.14-stable:
  Linux 4.14.193
  ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()
  ext4: fix direct I/O read error
  random32: move the pseudo-random 32-bit definitions to prandom.h
  random32: remove net_rand_state from the latent entropy gcc plugin
  random: fix circular include dependency on arm64 after addition of percpu.h
  ARM: percpu.h: fix build error
  random32: update the net random state on interrupt and activity
  Revert "scsi: libsas: direct call probe and destruct"

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-07 19:22:20 +05:30
Greg Kroah-Hartman
0d274200bf Merge 4.14.193 into android-4.14-stable
Changes in 4.14.193
	Revert "scsi: libsas: direct call probe and destruct"
	random32: update the net random state on interrupt and activity
	ARM: percpu.h: fix build error
	random: fix circular include dependency on arm64 after addition of percpu.h
	random32: remove net_rand_state from the latent entropy gcc plugin
	random32: move the pseudo-random 32-bit definitions to prandom.h
	ext4: fix direct I/O read error
	ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()
	Linux 4.14.193

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I4b4c5e1aa4379dba5af55d2c08bb9ae0119bc77d
2020-08-07 10:14:11 +02:00
Willy Tarreau
583bcbc024 random32: update the net random state on interrupt and activity
commit f227e3ec3b5cad859ad15666874405e8c1bbc1d4 upstream.

This modifies the first 32 bits out of the 128 bits of a random CPU's
net_rand_state on interrupt or CPU activity to complicate remote
observations that could lead to guessing the network RNG's internal
state.

Note that depending on some network devices' interrupt rate moderation
or binding, this re-seeding might happen on every packet or even almost
never.

In addition, with NOHZ some CPUs might not even get timer interrupts,
leaving their local state rarely updated, while they are running
networked processes making use of the random state.  For this reason, we
also perform this update in update_process_times() in order to at least
update the state when there is user or system activity, since it's the
only case we care about.

Reported-by: Amit Klein <aksecurity@gmail.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-08-07 09:38:41 +02:00
Lingutla Chandrasekhar
dffac07da2 sched: Improve the scheduler
This change is for general scheduler improvements.

Change-Id: If3a85c0d4aeb56e4b3493fa09bb295114edf2137
Signed-off-by: Lingutla Chandrasekhar <clingutla@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:32:17 +05:30
Satya Durga Srinivasu Prabhala
98f2b070e7 sched: Improve the scheduler
This change is for general scheduler improvements.

Change-Id: Iaefb893a84055748be7f2108179e3b869ac00318
Signed-off-by: Satya Durga Srinivasu Prabhala <satyap@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:05 +05:30
Maria Yu
0a3aef126b sched/fair: bonus vruntime for task boost 3
When task boost with special value 3 also have vruntime
bonus to run faster.

Change-Id: I7da2dd985a961671b27036a0d5b13cb79480c933
Signed-off-by: Maria Yu <aiquny@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:05 +05:30
blong
6b235d6248 Sched/fair: Improve the scheduler
This change is for general scheduler improvement.

Change-Id: Iefac9abcc7f4e3833e2434d0f508c493bdf0b28c
Signed-off-by: blong <blong@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:05 +05:30
blong
4ab420dd42 Sched/fair: Improve the scheduler
This change is for general scheduler improvements.

Change-Id: I95dca7ecedb3921196203cb5f2ed1b6b221b7703
Signed-off-by: blong <blong@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:05 +05:30
Pavankumar Kondeti
34e6577c89 sched/walt: Avoid taking rq lock for every IRQ update
sched_account_irqtime() is called for every IRQ/SoftIRQ update.
The rq->lock is needed only in idle context in which case
update_task_ravg() is called. For IRQ load updates, rq->lock
is not needed, since these are tracked per-cpu and migrations
are not applicable for irqload. By not taking rq lock for
every interrupt, we don't delay the irq exit path under heavy
rq lock contention. For example, this CPU is loaded with thousands
of tasks and rq->lock is acquired during load balance.

Change-Id: Iebba1a84408509ce93b3a8a0dcc1a9ea1f1bc930
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:05 +05:30
Pavankumar Kondeti
99e7949c12 sched/fair: Add timeout for detach_tasks() in load balance
When the busy CPU has thousands of tasks, the current loop break
of 32 does not scale nicely. Because each task deactivation may
take ~5 msec. Since this all happens from interrupts disabled
(from softirq also), it is resulting in watchdog bark. Hence
add 5 msec timeout in detach_tasks() to abort the load balance.

Change-Id: I290f75076f13a44d866dc4fe5fe6653733d28fbc
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 22:14:04 +05:30
UtsavBalar1231
c4b7c845a0 sm8150: squash remove place_marker usage
sed -i -e '/place_marker/d' $(git grep -l place_marker | tr '\n' ' ')
and manually remove snprintf() usage for boot marker

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 21:43:48 +05:30
Danny Lin
34a20308c3 f2fs: Add support for reporting a fake kernel version to fsck
fsck.f2fs forces a filesystem fix on boot if it detects that the current
kernel version differs from the one saved in the superblock, which results in
fsck blocking boot for a long time (~35 seconds). This commit provides a
way to report a constant fake kernel version to fsck to avoid triggering
the version check, which is useful if you boot new kernel builds
frequently.

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 20:22:28 +05:30
Danny Lin
8e639c1f3f cpufreq: schedutil: Expose default rate-limits as config options
This allows us to tune the default rate-limits without constantly
changing schedutil's code.

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-06 20:22:25 +05:30
UtsavBalar1231
cb5f044f80 cpufreq: squash revert cpu_input_boost support
Revert "cpu_input_boost: add prime core support"
Revert "cpu_input_boost: rewrite update_online_cpu_policy function"
Revert "cpu_input_boost: disable input boost of duration==0"
Revert "cpu_input_boost: add sm8150 support"
Revert "cpu_input_boost: add support for boost freqs lower than min freq"
Revert "cpu_input_boost: Mark boost kthread as performance critical"
Revert "cpu_input_boost: Introduce driver for event-based CPU boosting"
Revert "kernel: Boost to the max for a short amount of time when zygote forks"
Revert "kernel: Boost whenever a zygote-forked process becomes a top app"

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-05 20:50:42 +05:30
UtsavBalar1231
727a66e949 Merge remote-tracking branch 'origin/q' into auto-kernel
* origin/q:
  Linux 4.14.192
  x86/i8259: Use printk_deferred() to prevent deadlock
  KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled
  xen-netfront: fix potential deadlock in xennet_remove()
  cxgb4: add missing release on skb in uld_send()
  x86/unwind/orc: Fix ORC for newly forked tasks
  Revert "i2c: cadence: Fix the hold bit setting"
  net: ethernet: ravb: exit if re-initialization fails in tx timeout
  parisc: add support for cmpxchg on u8 pointers
  nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame
  qed: Disable "MFW indication via attention" SPAM every 5 minutes
  usb: hso: Fix debug compile warning on sparc32
  arm64: csum: Fix handling of bad packets
  arm64/alternatives: move length validation inside the subsection
  mac80211: mesh: Free pending skb when destroying a mpath
  mac80211: mesh: Free ie data when leaving mesh
  bpf: Fix map leak in HASH_OF_MAPS map
  ibmvnic: Fix IRQ mapping disposal in error path
  mlxsw: core: Free EMAD transactions using kfree_rcu()
  mlxsw: core: Increase scope of RCU read-side critical section
  mlx4: disable device on shutdown
  net: lan78xx: fix transfer-buffer memory leak
  net: lan78xx: add missing endpoint sanity check
  sh: Fix validation of system call number
  selftests/net: rxtimestamp: fix clang issues for target arch PowerPC
  net/x25: Fix null-ptr-deref in x25_disconnect
  net/x25: Fix x25_neigh refcnt leak when x25 disconnect
  xfs: fix missed wakeup on l_flush_wait
  rds: Prevent kernel-infoleak in rds_notify_queue_get()
  x86, vmlinux.lds: Page-align end of ..page_aligned sections
  x86/build/lto: Fix truncated .bss with -fdata-sections
  9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work
  9p/trans_fd: abort p9_read_work if req status changed
  f2fs: check if file namelen exceeds max value
  f2fs: check memory boundary by insane namelen
  drm: hold gem reference until object is no longer accessed
  drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()
  ARM: 8986/1: hw_breakpoint: Don't invoke overflow handler on uaccess watchpoints
  wireless: Use offsetof instead of custom macro.
  PCI/ASPM: Disable ASPM on ASMedia ASM1083/1085 PCIe-to-PCI bridge
  x86/kvm: Be careful not to clear KVM_VCPU_FLUSH_TLB bit
  ath9k: release allocated buffer if timed out
  ath9k_htc: release allocated buffer if timed out
  iio: imu: adis16400: fix memory leak
  media: rc: prevent memory leak in cx23888_ir_probe
  crypto: ccp - Release all allocated memory if sha type is invalid
  net: phy: mdio-bcm-unimac: fix potential NULL dereference in unimac_mdio_probe()
  scsi: libsas: direct call probe and destruct
  Revert "Dm: init: Enable rootfs mount as dm-verity during boot without ramdisk"
  msm: ep_pcie: set irq flag to IRQF_EARLY_RESUME for PERST irq
  mhi: cntrl: qcom: Update the fw image name for new devices
  drivers: qti-virtual-sensor: Add hexa cpu max virtual sensor for SDM429
  ARM: dts: msm: fix cx_cdev label size for SDM429W
  ARM: dts: msm: Add virtual display connector for sa8195
  usb: gadget: f_ipc: Increase max packet size to 24k
  usb: dwc3-msm: Set proper ssphy flag during peripheral bus suspend
  msm: qpnp-power-on: configure KPDPWR_N S2 for HARD_RESET at TWM entry
  power: smb1398: Update win-uv threshold to 10mV
  power: battery: Fix use of uninitialized variable error
  power: smb1398: Do not disable FP_FET during IREV condition
  backlight: qcom-spmi-wled: Add "qcom,sync-dly" property
  ARM: dts: msm: disable gpu_isdb cti for trinket
  net: qualcomm: rmnet: validate ipv6 extension header lengths
  msm: ais: Address index out of bounds
  binder: fix braces warning in binderfs
  usb: host: xhci: update event ring dequeue pointer on purpose
  iommu/arm-smmu: Do not write to slave side protected context banks
  i2c: i2c-qcom-geni: Reinitialize the variables after every transfer
  ARM: dts: msm: Add UFS support for kdump kernel on sa8155
  iio: adc: Add channels AMUX1 and AMUX3 for voltage reading
  msm: ADSPRPC: Size check before allocating memory from DMA
  sched/walt: Improve the scheduler
  drivers: soc: sdx_ext_ipc: Fix devm_request_threaded_irq call
  Reverting crypto and incrementalfs changes
  diag: Update event and log code ranges
  ARM: dts: msm: Update ADC channels for SA2150P based CCARD
  PCI: Add PCIe quirks for PCIe root port
  ARM: dts: msm: enable usb suspend function in host mode
  usb: dwc3-msm: Add markers for peripheral bus resume
  msm: vidc: fix deadlock between queue and flush buffer handling
  ARM: dts: msm: Add uart support for kdump kernel on sa8155
  sx150x-pinctrl: Avoid i2c transfer during kexec
  ARM: dts: msm: Add and enable Tj based modem_v2x mitigation for SA515
  drivers: thermal: qmi_cooling: Add support for modem_v2x cooling device
  arm: dts: qcom: add tz_apps and qseecom
  mhi: core: Error handling for pending packets in mission_mode
  msm: kgsl: Fix possible use-after-free while adding context to active list
  ARM: dts: msm: add support for SMP2P shutdown ack from modem
  ARM: dts: msm: Update mpss_adsp carved memory for sa515m cdp
  ARM: dts: msm: add hs uart node for BT on QCS410 device
  ARM: dts: msm: Add mem_dump and RTB node for sdm429
  defconfig: sdm429: Add configs related to DCVS and scheduler
  ARM : dts: msm: Add DCVS and sched nodes
  msm: ADSPRPC: Map and FD non-NULL check before dereferencing
  platform: msm: qcom-geni-se: Correct print statement format
  net: stmmac: Add check for micrel phy for phy interrupt
  defconfig: sdmshrike: use uncompressed linux kernel
  soc: qcom: hab: fix some issues in the remote open cancelling case
  wcnss: Enable smd channel ready
  ARM: dts: msm8916: Update reserved-memory for wcnss, venus and mba
  defconfig: Enable Incremental FS support
  ubifs: Fix deadlock in concurrent bulk-read and writepage
  spi: spi-geni-qcom: Return error if setup transfer fails
  mhi: core: do not toggle PCIe low power mode in sleeping context
  msm: ais: remove unnecessary writing to csid rdi cfg0 register
  cfg80211: Indicate backport support for sband iftype data
  ARM: dts: qcom: add display nodes for SDA429w devices
  init: early_services: get status after launching early services
  ARM: dts: msm: Add DVT-2 support for APQ hardware
  usb: phy: snps: Enable auto-resume during host mode bus suspend
  ARM: dts: msm: Add core/core2x clk for SSC QUP
  usb: misc: mdm_data_bridge: Add missing check for single interface
  msm: ais: add ais isp trace
  ARM: msm: dts: set skip-panel-reset for AUO 416p panel
  video: fbdev: msm: add skip-panel-reset dt property
  power: smb5-lib: Report the CURRENT_MAX as 1A in CC-mode
  soc: qcom: bgcom: Use shared_ee property for spi
  ARM: dts: msm: Add shared_ee property to bg spi node
  ARM: dts: msm: Add MHI and PCIe configuration
  video: fbdev: msm: add interface to send idle on/off command to panel
  msm: ipa3: Support uc header proc ctx for DSCP insertion
  usb: gadget: handle bam setup and cleanup for mbim in u_bam_dmux
  UPSTREAM: ath10k: Fix encoding for protected management frames
  UPSTREAM: ath10k: Fix length of wmi tlv command for protected mgmt frames
  UPSTREAM: ath10k: Add peer delete response event
  UPSTREAM: ath10k: wait for vdev delete response from firmware
  UPSTREAM: ath10k: Add wmi tlv service map for mesh 11s
  UPSTREAM: ath10k: update GCMP & GCMP-256 cipher suite number for WCN3990
  UPSTREAM: ath10k: assign 'n_cipher_suites = 11' for WCN3990 to enable WPA3
  UPSTREAM: ath10k: assign 'n_cipher_suites' for WCN3990
  UPSTREAM: ath10k: Add wmi tlv vdev subtype for mesh in WCN3990
  UPSTREAM: mac80211: add missing WFA Multi-AP backhaul STA Rx requirement
  usb: u_ether: Add null pointer check for sk_buff in eth_start_xmit
  kheaders: include only headers into kheaders_data.tar.xz
  kheaders: remove meaningless -R option of 'ls'
  msm: camera: Fix KW issues
  ARM: dts: msm: Change smem host id for gvm la
  soc: qcom: smem: Increase total host number
  kgsl: Parse secure mapping size from dts
  asoc: Add digital mute callback function for cdc dma
  usb: host: xhci: Increase number of event ring segments to 4
  soc: qcom: bgcom: use pm_runtime_status_suspended of spi
  net: usb: Initialize retval with zero as it might be used uninitialized
  ASoC: bolero: Resolve glitch during amic record
  msm: adsprpc: Race conditions when handling the ADSP SSR
  ASoC: bolero: Fix higher btn press noise issue
  audio-kernel: add proxy ports for call screening in machine driver
  asoc: add code change for proxy playback and capture BE DAIs.
  usb: pd: Correctly handle SVDM versions

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-05 20:50:30 +05:30
UtsavBalar1231
3ee3d0d45b Merge commit 'refs/changes/58/1391058/1' of https://android.googlesource.com/kernel/common into q
* https://android.googlesource.com/kernel/common:
  Linux 4.14.192
  x86/i8259: Use printk_deferred() to prevent deadlock
  KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled
  xen-netfront: fix potential deadlock in xennet_remove()
  cxgb4: add missing release on skb in uld_send()
  x86/unwind/orc: Fix ORC for newly forked tasks
  Revert "i2c: cadence: Fix the hold bit setting"
  net: ethernet: ravb: exit if re-initialization fails in tx timeout
  parisc: add support for cmpxchg on u8 pointers
  nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame
  qed: Disable "MFW indication via attention" SPAM every 5 minutes
  usb: hso: Fix debug compile warning on sparc32
  arm64: csum: Fix handling of bad packets
  arm64/alternatives: move length validation inside the subsection
  mac80211: mesh: Free pending skb when destroying a mpath
  mac80211: mesh: Free ie data when leaving mesh
  bpf: Fix map leak in HASH_OF_MAPS map
  ibmvnic: Fix IRQ mapping disposal in error path
  mlxsw: core: Free EMAD transactions using kfree_rcu()
  mlxsw: core: Increase scope of RCU read-side critical section
  mlx4: disable device on shutdown
  net: lan78xx: fix transfer-buffer memory leak
  net: lan78xx: add missing endpoint sanity check
  sh: Fix validation of system call number
  selftests/net: rxtimestamp: fix clang issues for target arch PowerPC
  net/x25: Fix null-ptr-deref in x25_disconnect
  net/x25: Fix x25_neigh refcnt leak when x25 disconnect
  xfs: fix missed wakeup on l_flush_wait
  rds: Prevent kernel-infoleak in rds_notify_queue_get()
  x86, vmlinux.lds: Page-align end of ..page_aligned sections
  x86/build/lto: Fix truncated .bss with -fdata-sections
  9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work
  9p/trans_fd: abort p9_read_work if req status changed
  f2fs: check if file namelen exceeds max value
  f2fs: check memory boundary by insane namelen
  drm: hold gem reference until object is no longer accessed
  drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()
  ARM: 8986/1: hw_breakpoint: Don't invoke overflow handler on uaccess watchpoints
  wireless: Use offsetof instead of custom macro.
  PCI/ASPM: Disable ASPM on ASMedia ASM1083/1085 PCIe-to-PCI bridge
  x86/kvm: Be careful not to clear KVM_VCPU_FLUSH_TLB bit
  ath9k: release allocated buffer if timed out
  ath9k_htc: release allocated buffer if timed out
  iio: imu: adis16400: fix memory leak
  media: rc: prevent memory leak in cx23888_ir_probe
  crypto: ccp - Release all allocated memory if sha type is invalid
  net: phy: mdio-bcm-unimac: fix potential NULL dereference in unimac_mdio_probe()
  scsi: libsas: direct call probe and destruct

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-05 20:26:29 +05:30
Greg Kroah-Hartman
f3c68e8b48 Merge 4.14.192 into android-4.14-stable
Changes in 4.14.192
	scsi: libsas: direct call probe and destruct
	net: phy: mdio-bcm-unimac: fix potential NULL dereference in unimac_mdio_probe()
	crypto: ccp - Release all allocated memory if sha type is invalid
	media: rc: prevent memory leak in cx23888_ir_probe
	iio: imu: adis16400: fix memory leak
	ath9k_htc: release allocated buffer if timed out
	ath9k: release allocated buffer if timed out
	x86/kvm: Be careful not to clear KVM_VCPU_FLUSH_TLB bit
	PCI/ASPM: Disable ASPM on ASMedia ASM1083/1085 PCIe-to-PCI bridge
	wireless: Use offsetof instead of custom macro.
	ARM: 8986/1: hw_breakpoint: Don't invoke overflow handler on uaccess watchpoints
	drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()
	drm: hold gem reference until object is no longer accessed
	f2fs: check memory boundary by insane namelen
	f2fs: check if file namelen exceeds max value
	9p/trans_fd: abort p9_read_work if req status changed
	9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work
	x86/build/lto: Fix truncated .bss with -fdata-sections
	x86, vmlinux.lds: Page-align end of ..page_aligned sections
	rds: Prevent kernel-infoleak in rds_notify_queue_get()
	xfs: fix missed wakeup on l_flush_wait
	net/x25: Fix x25_neigh refcnt leak when x25 disconnect
	net/x25: Fix null-ptr-deref in x25_disconnect
	selftests/net: rxtimestamp: fix clang issues for target arch PowerPC
	sh: Fix validation of system call number
	net: lan78xx: add missing endpoint sanity check
	net: lan78xx: fix transfer-buffer memory leak
	mlx4: disable device on shutdown
	mlxsw: core: Increase scope of RCU read-side critical section
	mlxsw: core: Free EMAD transactions using kfree_rcu()
	ibmvnic: Fix IRQ mapping disposal in error path
	bpf: Fix map leak in HASH_OF_MAPS map
	mac80211: mesh: Free ie data when leaving mesh
	mac80211: mesh: Free pending skb when destroying a mpath
	arm64/alternatives: move length validation inside the subsection
	arm64: csum: Fix handling of bad packets
	usb: hso: Fix debug compile warning on sparc32
	qed: Disable "MFW indication via attention" SPAM every 5 minutes
	nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame
	parisc: add support for cmpxchg on u8 pointers
	net: ethernet: ravb: exit if re-initialization fails in tx timeout
	Revert "i2c: cadence: Fix the hold bit setting"
	x86/unwind/orc: Fix ORC for newly forked tasks
	cxgb4: add missing release on skb in uld_send()
	xen-netfront: fix potential deadlock in xennet_remove()
	KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled
	x86/i8259: Use printk_deferred() to prevent deadlock
	Linux 4.14.192

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Iedf0bb8d6f4bea8e3d701d6b24dd365c2a920fc5
2020-08-05 14:38:44 +02:00
UtsavBalar1231
f04bf2d7c5 Merge tag 'LE.UM.3.2.3-45100-SA2150p' into q
"LE.UM.3.2.3-45100-SA2150p"

* tag 'LE.UM.3.2.3-45100-SA2150p' of https://source.codeaurora.org/quic/la/kernel/msm-4.14:
  msm: ep_pcie: set irq flag to IRQF_EARLY_RESUME for PERST irq
  mhi: cntrl: qcom: Update the fw image name for new devices
  drivers: qti-virtual-sensor: Add hexa cpu max virtual sensor for SDM429
  ARM: dts: msm: fix cx_cdev label size for SDM429W
  ARM: dts: msm: Add virtual display connector for sa8195
  usb: gadget: f_ipc: Increase max packet size to 24k
  usb: dwc3-msm: Set proper ssphy flag during peripheral bus suspend
  msm: qpnp-power-on: configure KPDPWR_N S2 for HARD_RESET at TWM entry
  power: smb1398: Update win-uv threshold to 10mV
  power: battery: Fix use of uninitialized variable error
  power: smb1398: Do not disable FP_FET during IREV condition
  backlight: qcom-spmi-wled: Add "qcom,sync-dly" property
  ARM: dts: msm: disable gpu_isdb cti for trinket
  net: qualcomm: rmnet: validate ipv6 extension header lengths
  msm: ais: Address index out of bounds
  binder: fix braces warning in binderfs
  usb: host: xhci: update event ring dequeue pointer on purpose
  iommu/arm-smmu: Do not write to slave side protected context banks
  i2c: i2c-qcom-geni: Reinitialize the variables after every transfer
  ARM: dts: msm: Add UFS support for kdump kernel on sa8155
  iio: adc: Add channels AMUX1 and AMUX3 for voltage reading
  msm: ADSPRPC: Size check before allocating memory from DMA
  sched/walt: Improve the scheduler
  drivers: soc: sdx_ext_ipc: Fix devm_request_threaded_irq call
  Reverting crypto and incrementalfs changes
  diag: Update event and log code ranges
  ARM: dts: msm: Update ADC channels for SA2150P based CCARD
  PCI: Add PCIe quirks for PCIe root port
  ARM: dts: msm: enable usb suspend function in host mode
  usb: dwc3-msm: Add markers for peripheral bus resume
  msm: vidc: fix deadlock between queue and flush buffer handling
  ARM: dts: msm: Add uart support for kdump kernel on sa8155
  sx150x-pinctrl: Avoid i2c transfer during kexec
  ARM: dts: msm: Add and enable Tj based modem_v2x mitigation for SA515
  drivers: thermal: qmi_cooling: Add support for modem_v2x cooling device
  arm: dts: qcom: add tz_apps and qseecom
  mhi: core: Error handling for pending packets in mission_mode
  msm: kgsl: Fix possible use-after-free while adding context to active list
  ARM: dts: msm: add support for SMP2P shutdown ack from modem
  ARM: dts: msm: Update mpss_adsp carved memory for sa515m cdp
  ARM: dts: msm: add hs uart node for BT on QCS410 device
  ARM: dts: msm: Add mem_dump and RTB node for sdm429
  defconfig: sdm429: Add configs related to DCVS and scheduler
  ARM : dts: msm: Add DCVS and sched nodes
  msm: ADSPRPC: Map and FD non-NULL check before dereferencing
  platform: msm: qcom-geni-se: Correct print statement format
  net: stmmac: Add check for micrel phy for phy interrupt
  defconfig: sdmshrike: use uncompressed linux kernel
  soc: qcom: hab: fix some issues in the remote open cancelling case
  wcnss: Enable smd channel ready
  ARM: dts: msm8916: Update reserved-memory for wcnss, venus and mba
  defconfig: Enable Incremental FS support
  ubifs: Fix deadlock in concurrent bulk-read and writepage
  spi: spi-geni-qcom: Return error if setup transfer fails
  mhi: core: do not toggle PCIe low power mode in sleeping context
  msm: ais: remove unnecessary writing to csid rdi cfg0 register
  cfg80211: Indicate backport support for sband iftype data
  ARM: dts: qcom: add display nodes for SDA429w devices
  init: early_services: get status after launching early services
  ARM: dts: msm: Add DVT-2 support for APQ hardware
  usb: phy: snps: Enable auto-resume during host mode bus suspend
  ARM: dts: msm: Add core/core2x clk for SSC QUP
  usb: misc: mdm_data_bridge: Add missing check for single interface
  msm: ais: add ais isp trace
  ARM: msm: dts: set skip-panel-reset for AUO 416p panel
  video: fbdev: msm: add skip-panel-reset dt property
  power: smb5-lib: Report the CURRENT_MAX as 1A in CC-mode
  soc: qcom: bgcom: Use shared_ee property for spi
  ARM: dts: msm: Add shared_ee property to bg spi node
  ARM: dts: msm: Add MHI and PCIe configuration
  video: fbdev: msm: add interface to send idle on/off command to panel
  msm: ipa3: Support uc header proc ctx for DSCP insertion
  usb: gadget: handle bam setup and cleanup for mbim in u_bam_dmux
  UPSTREAM: ath10k: Fix encoding for protected management frames
  UPSTREAM: ath10k: Fix length of wmi tlv command for protected mgmt frames
  UPSTREAM: ath10k: Add peer delete response event
  UPSTREAM: ath10k: wait for vdev delete response from firmware
  UPSTREAM: ath10k: Add wmi tlv service map for mesh 11s
  UPSTREAM: ath10k: update GCMP & GCMP-256 cipher suite number for WCN3990
  UPSTREAM: ath10k: assign 'n_cipher_suites = 11' for WCN3990 to enable WPA3
  UPSTREAM: ath10k: assign 'n_cipher_suites' for WCN3990
  UPSTREAM: ath10k: Add wmi tlv vdev subtype for mesh in WCN3990
  UPSTREAM: mac80211: add missing WFA Multi-AP backhaul STA Rx requirement
  usb: u_ether: Add null pointer check for sk_buff in eth_start_xmit
  kheaders: include only headers into kheaders_data.tar.xz
  kheaders: remove meaningless -R option of 'ls'
  msm: camera: Fix KW issues
  ARM: dts: msm: Change smem host id for gvm la
  soc: qcom: smem: Increase total host number
  kgsl: Parse secure mapping size from dts
  usb: host: xhci: Increase number of event ring segments to 4
  soc: qcom: bgcom: use pm_runtime_status_suspended of spi
  net: usb: Initialize retval with zero as it might be used uninitialized
  msm: adsprpc: Race conditions when handling the ADSP SSR
  usb: pd: Correctly handle SVDM versions

f2fs merge has been ignored as we are already inlined with f2fs-stable
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>

Conflicts:
	arch/arm64/boot/dts/qcom/sa8195p-adp-star-display.dtsi
	arch/arm64/configs/cuttlefish_defconfig
	drivers/md/Kconfig
	drivers/scsi/ufs/ufshcd.c
	fs/crypto/fscrypt_private.h
	fs/crypto/keyring.c
	fs/crypto/keysetup.c
	fs/crypto/keysetup_v1.c
	fs/ext4/inode.c
	fs/ext4/page-io.c
	fs/ext4/readpage.c
	fs/ext4/super.c
	fs/f2fs/data.c
	fs/f2fs/f2fs.h
	fs/f2fs/super.c
	include/linux/fscrypt.h
	include/uapi/linux/fscrypt.h
	kernel/time/alarmtimer.c
2020-08-05 16:15:20 +05:30
Andrii Nakryiko
e1aa01195b bpf: Fix map leak in HASH_OF_MAPS map
[ Upstream commit 1d4e1eab456e1ee92a94987499b211db05f900ea ]

Fix HASH_OF_MAPS bug of not putting inner map pointer on bpf_map_elem_update()
operation. This is due to per-cpu extra_elems optimization, which bypassed
free_htab_elem() logic doing proper clean ups. Make sure that inner map is put
properly in optimized case as well.

Fixes: 8c290e60fa ("bpf: fix hashmap extra_elems logic")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200729040913.2815687-1-andriin@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-08-05 10:06:51 +02:00
UtsavBalar1231
81ab5fb830 kernel: squash revert dynamic stune boost patches
Revert "ARM64: configs: raphael: Enable qcom CPU_BOOST"
Revert "ARM64: configs: raphael: Enable Dynamic Stune Booosting"
Revert "cpu-boost: reset to CAF"
Revert "cpu-boost: Create separate tunable for Dynamic Schedtune Boost duration"
Revert "cpu-boost: Update functions for newer Dynamic Schedtune Boost changes"
Revert "cpu-boost: Reset Dynamic SchedTune Boost only if it is currently active"
Revert "cpu-boost: Implement Dynamic SchedTune Boost v3"
Revert "sched/boost: Perform SchedTune boosting when sched_boost is triggered"
Revert "sched/tune: Switch Dynamic Schedtune Boost to a slot-based tracking system"
Revert "sched/stune: Rename stune_boost() to do_stune_sched_boost()"
Revert "sched/tune: Rename dynamic_boost parameter to sched_boost"
Revert "sched/tune: Track active boosts on a per-Schedtune basis"
Revert "sched/tune: Reset Dynamic Schedtune Boost only if no more boosts running"
Revert "sched/tune: Introduce stune_boost() function"
Revert "sched/tune: Refactor do_stune_boost()"
Revert "sched/tune: Create dynamic_boost SchedTune parameter"
Revert "sched/tune: Rename dynamic_boost_write() to dynamic_boost()"
Revert "sched/tune: Add initial support for Dynamic SchedTune Boost"

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-08-03 13:43:25 +05:30
UtsavBalar1231
068236c13a cpuset: guard CPUSETS_ASSISTANT code properly
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:33:58 +05:30
Peter Zijlstra
584386e654 sched/idle: Move quiet_vmstate() into the NOHZ code
quiet_vmstat() is an expensive function that only makes sense when we
go into NOHZ.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: aubrey.li@linux.intel.com
Cc: cl@linux.com
Cc: fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:33:57 +05:30
Peter Zijlstra
47e6534b72 idle: Prevent late-arriving interrupts from disrupting offline
Scheduling-clock interrupts can arrive late in the CPU-offline process,
after idle entry and the subsequent call to cpuhp_report_idle_dead().
Once execution passes the call to rcu_report_dead(), RCU is ignoring
the CPU, which results in lockdep complaints when the interrupt handler
uses RCU:

------------------------------------------------------------------------

=============================
WARNING: suspicious RCU usage
5.2.0-rc1+ #681 Not tainted
-----------------------------
kernel/sched/fair.c:9542 suspicious rcu_dereference_check() usage!

other info that might help us debug this:

RCU used illegally from offline CPU!
rcu_scheduler_active = 2, debug_locks = 1
no locks held by swapper/5/0.

stack backtrace:
CPU: 5 PID: 0 Comm: swapper/5 Not tainted 5.2.0-rc1+ #681
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS Bochs 01/01/2011
Call Trace:
 <IRQ>
 dump_stack+0x5e/0x8b
 trigger_load_balance+0xa8/0x390
 ? tick_sched_do_timer+0x60/0x60
 update_process_times+0x3b/0x50
 tick_sched_handle+0x2f/0x40
 tick_sched_timer+0x32/0x70
 __hrtimer_run_queues+0xd3/0x3b0
 hrtimer_interrupt+0x11d/0x270
 ? sched_clock_local+0xc/0x74
 smp_apic_timer_interrupt+0x79/0x200
 apic_timer_interrupt+0xf/0x20
 </IRQ>
RIP: 0010:delay_tsc+0x22/0x50
Code: ff 0f 1f 80 00 00 00 00 65 44 8b 05 18 a7 11 48 0f ae e8 0f 31 48 89 d6 48 c1 e6 20 48 09 c6 eb 0e f3 90 65 8b 05 fe a6 11 48 <41> 39 c0 75 18 0f ae e8 0f 31 48 c1 e2 20 48 09 c2 48 89 d0 48 29
RSP: 0000:ffff8f92c0157ed0 EFLAGS: 00000212 ORIG_RAX: ffffffffffffff13
RAX: 0000000000000005 RBX: ffff8c861f356400 RCX: ffff8f92c0157e64
RDX: 000000321214c8cc RSI: 00000032120daa7f RDI: 0000000000260f15
RBP: 0000000000000005 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000000
R13: 0000000000000000 R14: ffff8c861ee18000 R15: ffff8c861ee18000
 cpuhp_report_idle_dead+0x31/0x60
 do_idle+0x1d5/0x200
 ? _raw_spin_unlock_irqrestore+0x2d/0x40
 cpu_startup_entry+0x14/0x20
 start_secondary+0x151/0x170
 secondary_startup_64+0xa4/0xb0

------------------------------------------------------------------------

This happens rarely, but can be forced by happen more often by
placing delays in cpuhp_report_idle_dead() following the call to
rcu_report_dead().  With this in place, the following rcutorture
scenario reproduces the problem within a few minutes:

tools/testing/selftests/rcutorture/bin/kvm.sh --cpus 8 --duration 5 --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --configs "TREE04"

This commit uses the crude but effective expedient of moving the disabling
of interrupts within the idle loop to precede the cpu_is_offline()
check.  It also invokes tick_nohz_idle_stop_tick() instead of
tick_nohz_idle_stop_tick_protected() to shut off the scheduling-clock
interrupt.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
[ paulmck: Revert tick_nohz_idle_stop_tick_protected() removal, new callers. ]
Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:33:57 +05:30
Cheng Jian
163a8a3b3e FORWARDPORT: sched/idle: Micro-optimize the idle loop
Move the loop-invariant calculation of 'cpu' in do_idle() out of the loop body,
because the current CPU is always constant.

This improves the generated code both on x86-64 and ARM64:

x86-64:

Before patch (execution in loop):
	864:       0f ae e8                lfence
	867:       65 8b 05 c2 38 f1 7e    mov %gs:0x7ef138c2(%rip),%eax
	86e:       89 c0                   mov %eax,%eax
	870:       48 0f a3 05 68 19 08    bt  %rax,0x1081968(%rip)
	877:	   01

After patch (execution in loop):
	872:       0f ae e8                lfence
	875:       4c 0f a3 25 63 19 08    bt  %r12,0x1081963(%rip)
	87c:       01

ARM64:

Before patch (execution in loop):
	c58:       d5033d9f        dsb     ld
	c5c:       d538d080        mrs     x0, tpidr_el1
	c60:       b8606a61        ldr     w1, [x19,x0]
	c64:       1100fc20        add     w0, w1, #0x3f
	c68:       7100003f        cmp     w1, #0x0
	c6c:       1a81b000        csel    w0, w0, w1, lt
	c70:       13067c00        asr     w0, w0, #6
	c74:       93407c00        sxtw    x0, w0
	c78:       f8607a80        ldr     x0, [x20,x0,lsl #3]
	c7c:       9ac12401        lsr     x1, x0, x1
	c80:       36000581        tbz     w1, #0, d30 <do_idle+0x128>

After patch (execution in loop):
	c84:       d5033d9f        dsb     ld
	c88:       f9400260        ldr     x0, [x19]
	c8c:       ea14001f        tst     x0, x20
	c90:       54000580        b.eq    d40 <do_idle+0x138>

Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
[ Rewrote the title and the changelog. ]
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: huawei.libin@huawei.com
Cc: xiexiuqi@huawei.com
Link: http://lkml.kernel.org/r/1508930907-107755-1-git-send-email-cj.chengjian@huawei.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[yaro: moved the code around for 4.14 changes]
Signed-off-by: Yaroslav Furman <yaro330@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:33:57 +05:30
UtsavBalar1231
4696cad614 Revert "cpufreq: schedutil: Expose default configuration options and apply init protection"
This reverts commit 67d4ca95b2.

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:33:57 +05:30
RenderBroken
495e175f7c sched/boost: Perform SchedTune boosting when sched_boost is triggered
Boost top-app SchedTune tasks using the dynamic_boost value when
/proc/sys/kernel/sched_boost is activated. This is usually triggered by
CAF's perf daemon.

Signed-off-by: RenderBroken <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:46 +05:30
joshuous
5516cb37d1 sched/tune: Switch Dynamic Schedtune Boost to a slot-based tracking system
Switch from a counter-based system to a slot-based system for managing
multiple dynamic Schedtune boost requests.

The primary limitations of the counter-based system was that it could
only keep track of two boost values at a time: the current dynamic boost
value and the default boost value. When more than one boost request is
issued, the system would only remember the highest value of them all.
Even if the task that requested the highest value had unboosted, this
value is still maintained as long as there are other active boosts that
are still running. A more ideal outcome would be for the system to
unboost to the maximum boost value of the remaining active boosts.

The slot-based system provides a solution to the problem by keeping
track of the boost values of all ongoing active boosts. It ensures that
the current boost value will be equal to the maximum boost value of
all ongoing active boosts. This is achieved with two linked lists
(active_boost_slots and available_boost_slots), which assign and keep
track of boost slot numbers for each successful boost request. The boost
value of each request is stored in an array (slot_boost[]), at an index
value equal to the assigned boost slot number.

For now we limit the number of active boost slots to 5 per Schedtune
group.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:46 +05:30
joshuous
bfef06eede sched/stune: Rename stune_boost() to do_stune_sched_boost()
To reflect that the function is to be used mainly with CAF's devices
that have sched_boost. However, developers may use it as a switch to
dynamically boost schedtune to the values specified in
/dev/stune/*/schedtune.sched_boost.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
9ceb1e1d1e sched/tune: Rename dynamic_boost parameter to sched_boost
This was confusing to deal with given that it had the same name as the
Dynamic Schedtune Boost framework. It will be more apt to call it
sched_boost given that it was created to work with the sched_boost
feature in CAF devices.

The new tunable can be found in /dev/stune/*/schedtune.sched_boost

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
f939726069 sched/tune: Track active boosts on a per-Schedtune basis
It does not make sense to be unable to reset Schedtune boost for a
particular Schedtune group if another Schedtune group's boost is still
active. Instead of using a global count, we should use a per-Schedtune
group count to keep track of active boosts taking place.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
75a6b8d05d sched/tune: Reset Dynamic Schedtune Boost only if no more boosts running
We will need to take care to ensure that every do_stune_boost() we call
is followed eventually by a reset_stune_boost() so that
stune_boost_count is managed correctly.

This allows us to stack several Dynamic Schedtune Boosts and reset only
when all Dynamic Schedtune Boosts have been disengaged.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
199af8827d sched/tune: Introduce stune_boost() function
Add a simple function to activate Dynamic Schedtune Boost and use the
dynamic_boost value of the SchedTune CGroup.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
f5de1d3f26 sched/tune: Refactor do_stune_boost()
For added flexibility and in preparation for introducing another function.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
2ad49d363b sched/tune: Create dynamic_boost SchedTune parameter
Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
98c42dc2e5 sched/tune: Rename dynamic_boost_write() to dynamic_boost()
This is to reduce confusion when we create a new dynamic_boost_write()
function in future patches.

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:45 +05:30
joshuous
1acf51663a sched/tune: Add initial support for Dynamic SchedTune Boost
Provide functions to activate and reset SchedTune boost:

int do_stune_boost(char *st_name, int boost);
int reset_stune_boost(char *st_name);

Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:24 +05:30
UtsavBalar1231
e93c392d0b cpu-boost: reset to CAF
Revert "cpufreq: cpu-boost: Handle KEY_WAKEUP keycode"
Revert "cpu-boost: add powerkey cpuboost with reworked scheduling setup"
Revert "cpu-boost: Reduce input boost time interval"
Revert "cpu-boost: Bind to LITTLE cpus and reduce RT prio"
Revert "cpu-boost: Rework scheduling setup"

Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:19 +05:30
celtare21
9c9430f753 kernel: Force sched_walt_rotate_big_tasks to 0
Signed-off-by: celtare21 <celtare21@gmail.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:02:13 +05:30
Miguel de Dios
aa29de8f0e sched: reduce softirq conflicts with RT
This is a forward port of pa/890483 with modifications from the original
patch due to changes in sched/softirq.c which applies the same logic.

We're finding audio glitches caused by audio-producing RT tasks
that are either interrupted to handle softirq's or that are
scheduled onto cpu's that are handling softirq's.
In a previous patch, we attempted to catch many cases of the
latter problem, but it's clear that we are still losing
significant numbers of races in some apps.

This patch attempts to address the following problem::
   It attempts to reduce the most common windows in which
   we lose the race between scheduling an RT task on a remote
   core and starting to handle softirq's on that core.
   We still lose some races, but we lose significantly fewer.
   (And we don't want to introduce any heavyweight forms
   of synchronization on these paths.)

Bug: 64912585
Bug: 136771796
Change-Id: Ida89a903be0f1965552dd0e84e67ef1d3158c7d8
Signed-off-by: Miguel de Dios <migueldedios@google.com>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
2020-07-30 14:01:42 +05:30