1. 26 7月, 2018 4 次提交
  2. 13 6月, 2018 3 次提交
    • K
      treewide: Use array_size() in vmalloc() · 42bc47b3
      Kees Cook 提交于
      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: NKees Cook <keescook@chromium.org>
      42bc47b3
    • K
      treewide: devm_kzalloc() -> devm_kcalloc() · a86854d0
      Kees Cook 提交于
      The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
      This patch replaces cases of:
      
              devm_kzalloc(handle, a * b, gfp)
      
      with:
              devm_kcalloc(handle, a * b, gfp)
      
      as well as handling cases of:
      
              devm_kzalloc(handle, a * b * c, gfp)
      
      with:
      
              devm_kzalloc(handle, array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              devm_kcalloc(handle, array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              devm_kzalloc(handle, 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.
      
      Some manual whitespace fixes were needed in this patch, as Coccinelle
      really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      expression HANDLE;
      type TYPE;
      expression THING, E;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression HANDLE;
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      expression HANDLE;
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      expression HANDLE;
      identifier SIZE, COUNT;
      @@
      
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression HANDLE;
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression HANDLE;
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      expression HANDLE;
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	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 HANDLE;
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	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 HANDLE;
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
      |
        devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2, ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      a86854d0
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      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: NKees Cook <keescook@chromium.org>
      6396bb22
  3. 12 6月, 2018 1 次提交
    • L
      Revert "iommu/amd_iommu: Use CONFIG_DMA_DIRECT_OPS=y and dma_direct_{alloc,free}()" · e16c4790
      Linus Torvalds 提交于
      This reverts commit b468620f.
      
      It turns out that this broke drm on AMD platforms. Quoting Gabriel C:
       "I can confirm reverting b468620f fixes
        that issue for me.
      
        The GPU is working fine with SME enabled.
      
        Now with working GPU :) I can also confirm performance is back to
        normal without doing any other workarounds"
      
      Christan König analyzed it partially:
       "As far as I analyzed it we now get an -ENOMEM from dma_alloc_attrs()
        in drivers/gpu/drm/ttm/ttm_page_alloc_dma.c when IOMMU is enabled"
      
      and Christoph Hellwig responded:
       "I think the prime issue is that dma_direct_alloc respects the dma
        mask. Which we don't need if actually using the iommu. This would be
        mostly harmless exept for the the SEV bit high in the address that
        makes the checks fail.
      
        For now I'd say revert this commit for 4.17/4.18-rc and I'll look into
        addressing these issues properly"
      Reported-and-bisected-by: NGabriel C <nix.or.die@gmail.com>
      Acked-by: NChristoph Hellwig <hch@lst.de>
      Cc: Christian König <christian.koenig@amd.com>
      Cc: Michel Dänzer <michel.daenzer@amd.com>
      Cc: Joerg Roedel <jroedel@suse.de>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: stable@kernel.org		# v4.17
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e16c4790
  4. 06 6月, 2018 1 次提交
    • T
      irq_remapping: Use apic_ack_irq() · 8a2b7d14
      Thomas Gleixner 提交于
      To address the EBUSY fail of interrupt affinity settings in case that the
      previous setting has not been cleaned up yet, use the new apic_ack_irq()
      function instead of the special ir_ack_apic_edge() implementation which is
      merily a wrapper around ack_APIC_irq().
      
      Preparatory change for the real fix
      
      Fixes: dccfe314 ("x86/vector: Simplify vector move cleanup")
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Tested-by: NSong Liu <songliubraving@fb.com>
      Cc: Joerg Roedel <jroedel@suse.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <liu.song.a23@gmail.com>
      Cc: Dmitry Safonov <0x7f454c46@gmail.com>
      Cc: stable@vger.kernel.org
      Cc: Mike Travis <mike.travis@hpe.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Tariq Toukan <tariqt@mellanox.com>
      Link: https://lkml.kernel.org/r/20180604162224.555716895@linutronix.de
      8a2b7d14
  5. 29 5月, 2018 1 次提交
    • R
      iommu/io-pgtable-arm: Make allocations NUMA-aware · 4b123757
      Robin Murphy 提交于
      We would generally expect pagetables to be read by the IOMMU more than
      written by the CPU, so in NUMA systems it makes sense to locate them
      close to the former and avoid cross-node pagetable walks if at all
      possible. As it turns out, we already have a handle on the IOMMU device
      for the sake of coherency management, so it's trivial to grab the
      appropriate NUMA node when allocating new pagetable pages.
      
      Note that we drop the semantics of alloc_pages_exact(), but that's fine
      since they have never been necessary: the only time we're allocating
      more than one page is for stage 2 top-level concatenation, but since
      that is based on the number of IPA bits, the size is always some exact
      power of two anyway.
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      4b123757
  6. 15 5月, 2018 9 次提交
  7. 11 5月, 2018 1 次提交
    • G
      PCI: Add "pci=noats" boot parameter · cef74409
      Gil Kupfer 提交于
      Adds a "pci=noats" boot parameter.  When supplied, all ATS related
      functions fail immediately and the IOMMU is configured to not use
      device-IOTLB.
      
      Any function that checks for ATS capabilities directly against the devices
      should also check this flag.  Currently, such functions exist only in IOMMU
      drivers, and they are covered by this patch.
      
      The motivation behind this patch is the existence of malicious devices.
      Lots of research has been done about how to use the IOMMU as protection
      from such devices.  When ATS is supported, any I/O device can access any
      physical address by faking device-IOTLB entries.  Adding the ability to
      ignore these entries lets sysadmins enhance system security.
      Signed-off-by: NGil Kupfer <gilkup@cs.technion.ac.il>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Acked-by: NJoerg Roedel <jroedel@suse.de>
      cef74409
  8. 09 5月, 2018 1 次提交
  9. 03 5月, 2018 15 次提交
    • A
      iommu: rockchip: fix building without CONFIG_OF · 40fa84e1
      Arnd Bergmann 提交于
      We get a build error when compiling the iommu driver without CONFIG_OF:
      
      drivers/iommu/rockchip-iommu.c: In function 'rk_iommu_of_xlate':
      drivers/iommu/rockchip-iommu.c:1101:2: error: implicit declaration of function 'of_dev_put'; did you mean 'of_node_put'? [-Werror=implicit-function-declaration]
      
      This replaces the of_dev_put() with the equivalent
      platform_device_put().
      
      Fixes: 5fd577c3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      40fa84e1
    • G
      iommu/amd: Update logging information for new event type · e7f63ffc
      Gary R Hook 提交于
      A new events have been defined in the AMD IOMMU spec:
      
      0x09 - "invalid PPR request"
      
      Add support for logging this type of event.
      Signed-off-by: NGary R Hook <gary.hook@amd.com>
      ~
      ~
      ~
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      e7f63ffc
    • G
      iommu/amd: Update the PASID information printed to the system log · d64c0486
      Gary R Hook 提交于
      Provide detailed data for each event, as appropriate.
      Signed-off-by: NGary R Hook <gary.hook@amd.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      d64c0486
    • J
      iommu/vt-d: Use WARN_ON_ONCE instead of BUG_ON in qi_flush_dev_iotlb() · a85894cd
      Joerg Roedel 提交于
      A misaligned address is only worth a warning, and not
      stopping the while execution path with a BUG_ON().
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      a85894cd
    • C
      iommu/vt-d: fix shift-out-of-bounds in bug checking · 0dfc0c79
      Changbin Du 提交于
      It allows to flush more than 4GB of device TLBs. So the mask should be
      64bit wide. UBSAN captured this fault as below.
      
      [    3.760024] ================================================================================
      [    3.768440] UBSAN: Undefined behaviour in drivers/iommu/dmar.c:1348:3
      [    3.774864] shift exponent 64 is too large for 32-bit type 'int'
      [    3.780853] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G     U            4.17.0-rc1+ #89
      [    3.788661] Hardware name: Dell Inc. OptiPlex 7040/0Y7WYT, BIOS 1.2.8 01/26/2016
      [    3.796034] Call Trace:
      [    3.798472]  <IRQ>
      [    3.800479]  dump_stack+0x90/0xfb
      [    3.803787]  ubsan_epilogue+0x9/0x40
      [    3.807353]  __ubsan_handle_shift_out_of_bounds+0x10e/0x170
      [    3.812916]  ? qi_flush_dev_iotlb+0x124/0x180
      [    3.817261]  qi_flush_dev_iotlb+0x124/0x180
      [    3.821437]  iommu_flush_dev_iotlb+0x94/0xf0
      [    3.825698]  iommu_flush_iova+0x10b/0x1c0
      [    3.829699]  ? fq_ring_free+0x1d0/0x1d0
      [    3.833527]  iova_domain_flush+0x25/0x40
      [    3.837448]  fq_flush_timeout+0x55/0x160
      [    3.841368]  ? fq_ring_free+0x1d0/0x1d0
      [    3.845200]  ? fq_ring_free+0x1d0/0x1d0
      [    3.849034]  call_timer_fn+0xbe/0x310
      [    3.852696]  ? fq_ring_free+0x1d0/0x1d0
      [    3.856530]  run_timer_softirq+0x223/0x6e0
      [    3.860625]  ? sched_clock+0x5/0x10
      [    3.864108]  ? sched_clock+0x5/0x10
      [    3.867594]  __do_softirq+0x1b5/0x6f5
      [    3.871250]  irq_exit+0xd4/0x130
      [    3.874470]  smp_apic_timer_interrupt+0xb8/0x2f0
      [    3.879075]  apic_timer_interrupt+0xf/0x20
      [    3.883159]  </IRQ>
      [    3.885255] RIP: 0010:poll_idle+0x60/0xe7
      [    3.889252] RSP: 0018:ffffb1b201943e30 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff13
      [    3.896802] RAX: 0000000080200000 RBX: 000000000000008e RCX: 000000000000001f
      [    3.903918] RDX: 0000000000000000 RSI: 000000002819aa06 RDI: 0000000000000000
      [    3.911031] RBP: ffff9e93c6b33280 R08: 00000010f717d567 R09: 000000000010d205
      [    3.918146] R10: ffffb1b201943df8 R11: 0000000000000001 R12: 00000000e01b169d
      [    3.925260] R13: 0000000000000000 R14: ffffffffb12aa400 R15: 0000000000000000
      [    3.932382]  cpuidle_enter_state+0xb4/0x470
      [    3.936558]  do_idle+0x222/0x310
      [    3.939779]  cpu_startup_entry+0x78/0x90
      [    3.943693]  start_secondary+0x205/0x2e0
      [    3.947607]  secondary_startup_64+0xa5/0xb0
      [    3.951783] ================================================================================
      Signed-off-by: NChangbin Du <changbin.du@intel.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      0dfc0c79
    • S
      iommu/dma: Move PCI window region reservation back into dma specific path. · cd2c9fcf
      Shameer Kolothum 提交于
      This pretty much reverts commit 273df963 ("iommu/dma: Make PCI
      window reservation generic")  by moving the PCI window region
      reservation back into the dma specific path so that these regions
      doesn't get exposed via the IOMMU API interface. With this change,
      the vfio interface will report only iommu specific reserved regions
      to the user space.
      
      Cc: Joerg Roedel <joro@8bytes.org>
      Signed-off-by: NShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Fixes: 273df963 ('iommu/dma: Make PCI window reservation generic')
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      cd2c9fcf
    • H
      iommu/rockchip: Make clock handling optional · 2f8c7f2e
      Heiko Stuebner 提交于
      iommu clocks are optional, so the driver should not fail if they are not
      present. Instead just set the number of clocks to 0, which the clk-blk APIs
      can handle just fine.
      
      Fixes: f2e3a5f5 ("iommu/rockchip: Control clocks needed to access the IOMMU")
      Signed-off-by: NHeiko Stuebner <heiko@sntech.de>
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Tested-by: NEnric Balletbo i Serra <enric.balletbo@collabora.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      2f8c7f2e
    • A
      iommu/amd: Hide unused iommu_table_lock · 94c793ac
      Arnd Bergmann 提交于
      The newly introduced lock is only used when CONFIG_IRQ_REMAP is enabled:
      
      drivers/iommu/amd_iommu.c:86:24: error: 'iommu_table_lock' defined but not used [-Werror=unused-variable]
       static DEFINE_SPINLOCK(iommu_table_lock);
      
      This moves the definition next to the user, within the #ifdef protected
      section of the file.
      
      Fixes: ea6166f4 ("iommu/amd: Split irq_lookup_table out of the amd_iommu_devtable_lock")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Acked-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      94c793ac
    • J
      iommu/vt-d: Fix usage of force parameter in intel_ir_reconfigure_irte() · aa7528fe
      Jagannathan Raman 提交于
      It was noticed that the IRTE configured for guest OS kernel
      was over-written while the guest was running. As a result,
      vt-d Posted Interrupts configured for the guest are not being
      delivered directly, and instead bounces off the host. Every
      interrupt delivery takes a VM Exit.
      
      It was noticed that the following stack is doing the over-write:
      [  147.463177]  modify_irte+0x171/0x1f0
      [  147.463405]  intel_ir_set_affinity+0x5c/0x80
      [  147.463641]  msi_domain_set_affinity+0x32/0x90
      [  147.463881]  irq_do_set_affinity+0x37/0xd0
      [  147.464125]  irq_set_affinity_locked+0x9d/0xb0
      [  147.464374]  __irq_set_affinity+0x42/0x70
      [  147.464627]  write_irq_affinity.isra.5+0xe1/0x110
      [  147.464895]  proc_reg_write+0x38/0x70
      [  147.465150]  __vfs_write+0x36/0x180
      [  147.465408]  ? handle_mm_fault+0xdf/0x200
      [  147.465671]  ? _cond_resched+0x15/0x30
      [  147.465936]  vfs_write+0xad/0x1a0
      [  147.466204]  SyS_write+0x52/0xc0
      [  147.466472]  do_syscall_64+0x74/0x1a0
      [  147.466744]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
      
      reversing the sense of force check in intel_ir_reconfigure_irte()
      restores proper posted interrupt functionality
      Signed-off-by: NJagannathan Raman <jag.raman@oracle.com>
      Fixes: d491bdff ('iommu/vt-d: Reevaluate vector configuration on activate()')
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      aa7528fe
    • D
      iommu/tegra: gart: Fix gart_iommu_unmap() · 130a2fdf
      Dmitry Osipenko 提交于
      It must return the number of unmapped bytes on success, returning 0 means
      that unmapping failed and in result only one page is unmapped.
      Signed-off-by: NDmitry Osipenko <digetx@gmail.com>
      Reviewed-by: NThierry Reding <treding@nvidia.com>
      Acked-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      130a2fdf
    • D
      iommu/tegra: gart: Add debugging facility · 40c9b882
      Dmitry Osipenko 提交于
      Page mapping could overwritten by an accident (a bug). We can catch this
      case by checking 'VALID' bit of GART's page entry prior to mapping of a
      page. Since that check introduces a small performance impact, it should be
      enabled explicitly using new GART's kernel module 'debug' parameter.
      Signed-off-by: NDmitry Osipenko <digetx@gmail.com>
      Acked-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      40c9b882
    • Y
      iommu/io-pgtable-arm: Use for_each_set_bit to simplify code · f793b13e
      YueHaibing 提交于
      We can use for_each_set_bit() to simplify code slightly in the
      ARM io-pgtable self tests while unmapping.
      Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      f793b13e
    • W
      iommu/qcom: Simplify getting .drvdata · 7d1bf14f
      Wolfram Sang 提交于
      We should get drvdata from struct device directly. Going via
      platform_device is an unneeded step back and forth.
      Signed-off-by: NWolfram Sang <wsa+renesas@sang-engineering.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      7d1bf14f
    • G
      iommu: Remove depends on HAS_DMA in case of platform dependency · 48e6f765
      Geert Uytterhoeven 提交于
      Remove dependencies on HAS_DMA where a Kconfig symbol depends on another
      symbol that implies HAS_DMA, and, optionally, on "|| COMPILE_TEST".
      In most cases this other symbol is an architecture or platform specific
      symbol, or PCI.
      
      Generic symbols and drivers without platform dependencies keep their
      dependencies on HAS_DMA, to prevent compiling subsystems or drivers that
      cannot work anyway.
      
      This simplifies the dependencies, and allows to improve compile-testing.
      Signed-off-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Reviewed-by: NMark Brown <broonie@kernel.org>
      Acked-by: NRobin Murphy <robin.murphy@arm.com>
      Acked-by: NJoerg Roedel <jroedel@suse.de>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      48e6f765
    • D
      iommu/vt-d: Ratelimit each dmar fault printing · 6c50d79f
      Dmitry Safonov 提交于
      There is a ratelimit for printing, but it's incremented each time the
      cpu recives dmar fault interrupt. While one interrupt may signal about
      *many* faults.
      So, measuring the impact it turns out that reading/clearing one fault
      takes < 1 usec, and printing info about the fault takes ~170 msec.
      
      Having in mind that maximum number of fault recording registers per
      remapping hardware unit is 256.. IRQ handler may run for (170*256) msec.
      And as fault-serving loop runs without a time limit, during servicing
      new faults may occur..
      
      Ratelimit each fault printing rather than each irq printing.
      
      Fixes: commit c43fce4e ("iommu/vt-d: Ratelimit fault handler")
      
      BUG: spinlock lockup suspected on CPU#0, CliShell/9903
       lock: 0xffffffff81a47440, .magic: dead4ead, .owner: kworker/u16:2/8915, .owner_cpu: 6
      CPU: 0 PID: 9903 Comm: CliShell
      Call Trace:$\n'
      [..] dump_stack+0x65/0x83$\n'
      [..] spin_dump+0x8f/0x94$\n'
      [..] do_raw_spin_lock+0x123/0x170$\n'
      [..] _raw_spin_lock_irqsave+0x32/0x3a$\n'
      [..] uart_chars_in_buffer+0x20/0x4d$\n'
      [..] tty_chars_in_buffer+0x18/0x1d$\n'
      [..] n_tty_poll+0x1cb/0x1f2$\n'
      [..] tty_poll+0x5e/0x76$\n'
      [..] do_select+0x363/0x629$\n'
      [..] compat_core_sys_select+0x19e/0x239$\n'
      [..] compat_SyS_select+0x98/0xc0$\n'
      [..] sysenter_dispatch+0x7/0x25$\n'
      [..]
      NMI backtrace for cpu 6
      CPU: 6 PID: 8915 Comm: kworker/u16:2
      Workqueue: dmar_fault dmar_fault_work
      Call Trace:$\n'
      [..] wait_for_xmitr+0x26/0x8f$\n'
      [..] serial8250_console_putchar+0x1c/0x2c$\n'
      [..] uart_console_write+0x40/0x4b$\n'
      [..] serial8250_console_write+0xe6/0x13f$\n'
      [..] call_console_drivers.constprop.13+0xce/0x103$\n'
      [..] console_unlock+0x1f8/0x39b$\n'
      [..] vprintk_emit+0x39e/0x3e6$\n'
      [..] printk+0x4d/0x4f$\n'
      [..] dmar_fault+0x1a8/0x1fc$\n'
      [..] dmar_fault_work+0x15/0x17$\n'
      [..] process_one_work+0x1e8/0x3a9$\n'
      [..] worker_thread+0x25d/0x345$\n'
      [..] kthread+0xea/0xf2$\n'
      [..] ret_from_fork+0x58/0x90$\n'
      
      Cc: Alex Williamson <alex.williamson@redhat.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Lu Baolu <baolu.lu@linux.intel.com>
      Cc: iommu@lists.linux-foundation.org
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      6c50d79f
  10. 06 4月, 2018 1 次提交
    • R
      headers: untangle kmemleak.h from mm.h · 514c6032
      Randy Dunlap 提交于
      Currently <linux/slab.h> #includes <linux/kmemleak.h> for no obvious
      reason.  It looks like it's only a convenience, so remove kmemleak.h
      from slab.h and add <linux/kmemleak.h> to any users of kmemleak_* that
      don't already #include it.  Also remove <linux/kmemleak.h> from source
      files that do not use it.
      
      This is tested on i386 allmodconfig and x86_64 allmodconfig.  It would
      be good to run it through the 0day bot for other $ARCHes.  I have
      neither the horsepower nor the storage space for the other $ARCHes.
      
      Update: This patch has been extensively build-tested by both the 0day
      bot & kisskb/ozlabs build farms.  Both of them reported 2 build failures
      for which patches are included here (in v2).
      
      [ slab.h is the second most used header file after module.h; kernel.h is
        right there with slab.h. There could be some minor error in the
        counting due to some #includes having comments after them and I didn't
        combine all of those. ]
      
      [akpm@linux-foundation.org: security/keys/big_key.c needs vmalloc.h, per sfr]
      Link: http://lkml.kernel.org/r/e4309f98-3749-93e1-4bb7-d9501a39d015@infradead.org
      Link: http://kisskb.ellerman.id.au/kisskb/head/13396/Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Reviewed-by: NIngo Molnar <mingo@kernel.org>
      Reported-by: Michael Ellerman <mpe@ellerman.id.au>	[2 build failures]
      Reported-by: Fengguang Wu <fengguang.wu@intel.com>	[2 build failures]
      Reviewed-by: NAndrew Morton <akpm@linux-foundation.org>
      Cc: Wei Yongjun <weiyongjun1@huawei.com>
      Cc: Luis R. Rodriguez <mcgrof@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: John Johansen <john.johansen@canonical.com>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      514c6032
  11. 29 3月, 2018 3 次提交