All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@linux.intel.com>
To: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: thomas.hellstrom@linux.intel.com, keescook@chromium.org,
	jani.nikula@intel.com, ndesaulniers@google.com,
	intel-gfx@lists.freedesktop.org, linux@rasmusvillemoes.dk,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	chris@chris-wilson.co.uk, andrzej.hajda@intel.com,
	dlatypov@google.com, matthew.auld@intel.com, daniel@ffwll.ch,
	airlied@redhat.com, mchehab@kernel.org, vitor@massaru.org,
	nirmoy.das@intel.com
Subject: Re: [Intel-gfx] [PATCH v10 3/9] compiler_types.h: Add assert_type to catch type mis-match while compiling
Date: Sun, 11 Sep 2022 13:04:55 +0200	[thread overview]
Message-ID: <Yx3A16ZElKOeJr0o@alfio.lan> (raw)
In-Reply-To: <20220909105913.752049-4-gwan-gyeong.mun@intel.com>

Hi Gwan-gyeong,

On Fri, Sep 09, 2022 at 07:59:07PM +0900, Gwan-gyeong Mun wrote:
> It adds assert_type and assert_typable macros to catch type mis-match while

/Add/It adds/, please use the imperative form.

> compiling. The existing typecheck() macro outputs build warnings, but the
> newly added assert_type() macro uses the _Static_assert() keyword (which is
> introduced in C11) to generate a build break when the types are different
> and can be used to detect explicit build errors.
> Unlike the assert_type() macro, assert_typable() macro allows a constant
> value as the second argument.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Kees Cook <keescook@chromium.org>
> ---
>  include/linux/compiler_types.h | 39 ++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index 4f2a819fd60a..19cc125918bb 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -294,6 +294,45 @@ struct ftrace_likely_data {
>  /* Are two types/vars the same type (ignoring qualifiers)? */
>  #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
>  
> +/**
> + * assert_type - break compile if the first argument's data type and the second
> + *               argument's data type are not the same

I would use /aborts compilation/break compile/

> + *

nowhere is written that this extra blank line is not needed, but
just checking the style in compiler_types.h it is not used.

I personally like the blank line, but standing to the general
taste, it should be removed also for keeping a coherent style.

> + * @t1: data type or variable
> + * @t2: data type or variable
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). It determines whether the first argument's data type and the second
> + * argument's data type are the same while compiling, and it breaks compile if
> + * the two types are not the same.
> + * See also assert_typable().
> + */
> +#define assert_type(t1, t2) _Static_assert(__same_type(t1, t2))

In C11 _Static_assert is defined as:

  _Static_assert ( constant-expression , string-literal ) ;

While

  _Static_assert ( constant-expression ) ;

is defined in C17 along with the previous. I think you should add
the error message as a 'string-literal'.

Andi

> +/**
> + * assert_typable - break compile if the first argument's data type and the
> + *                  second argument's data type are not the same
> + *
> + * @t: data type or variable
> + * @n: data type or variable or constant value
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). Unlike the assert_type() macro, this macro allows a constant value
> + * as the second argument. And if the second argument is a constant value, it
> + * always passes. And it doesn't mean that the types are explicitly the same.
> + * When a constant value is used as the second argument, if you need an
> + * overflow check when assigning a constant value to a variable of the type of
> + * the first argument, you can use the overflows_type() macro. When a constant
> + * value is not used as a second argument, it determines whether the first
> + * argument's data type and the second argument's data type are the same while
> + * compiling, and it breaks compile if the two types are not the same.
> + * See also assert_type() and overflows_type().
> + */
> +#define assert_typable(t, n) _Static_assert(__builtin_constant_p(n) ||	\
> +					    __same_type(t, typeof(n)))
> +
>  /*
>   * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
>   *			       non-scalar types unchanged.
> -- 
> 2.37.1

WARNING: multiple messages have this Message-ID (diff)
From: Andi Shyti <andi.shyti@linux.intel.com>
To: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: thomas.hellstrom@linux.intel.com, mauro.chehab@linux.intel.com,
	andi.shyti@linux.intel.com, keescook@chromium.org,
	jani.nikula@intel.com, ndesaulniers@google.com,
	intel-gfx@lists.freedesktop.org, linux@rasmusvillemoes.dk,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	chris@chris-wilson.co.uk, andrzej.hajda@intel.com,
	dlatypov@google.com, matthew.auld@intel.com, airlied@redhat.com,
	mchehab@kernel.org, vitor@massaru.org, nirmoy.das@intel.com
Subject: Re: [PATCH v10 3/9] compiler_types.h: Add assert_type to catch type mis-match while compiling
Date: Sun, 11 Sep 2022 13:04:55 +0200	[thread overview]
Message-ID: <Yx3A16ZElKOeJr0o@alfio.lan> (raw)
In-Reply-To: <20220909105913.752049-4-gwan-gyeong.mun@intel.com>

Hi Gwan-gyeong,

On Fri, Sep 09, 2022 at 07:59:07PM +0900, Gwan-gyeong Mun wrote:
> It adds assert_type and assert_typable macros to catch type mis-match while

/Add/It adds/, please use the imperative form.

> compiling. The existing typecheck() macro outputs build warnings, but the
> newly added assert_type() macro uses the _Static_assert() keyword (which is
> introduced in C11) to generate a build break when the types are different
> and can be used to detect explicit build errors.
> Unlike the assert_type() macro, assert_typable() macro allows a constant
> value as the second argument.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Kees Cook <keescook@chromium.org>
> ---
>  include/linux/compiler_types.h | 39 ++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index 4f2a819fd60a..19cc125918bb 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -294,6 +294,45 @@ struct ftrace_likely_data {
>  /* Are two types/vars the same type (ignoring qualifiers)? */
>  #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
>  
> +/**
> + * assert_type - break compile if the first argument's data type and the second
> + *               argument's data type are not the same

I would use /aborts compilation/break compile/

> + *

nowhere is written that this extra blank line is not needed, but
just checking the style in compiler_types.h it is not used.

I personally like the blank line, but standing to the general
taste, it should be removed also for keeping a coherent style.

> + * @t1: data type or variable
> + * @t2: data type or variable
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). It determines whether the first argument's data type and the second
> + * argument's data type are the same while compiling, and it breaks compile if
> + * the two types are not the same.
> + * See also assert_typable().
> + */
> +#define assert_type(t1, t2) _Static_assert(__same_type(t1, t2))

In C11 _Static_assert is defined as:

  _Static_assert ( constant-expression , string-literal ) ;

While

  _Static_assert ( constant-expression ) ;

is defined in C17 along with the previous. I think you should add
the error message as a 'string-literal'.

Andi

> +/**
> + * assert_typable - break compile if the first argument's data type and the
> + *                  second argument's data type are not the same
> + *
> + * @t: data type or variable
> + * @n: data type or variable or constant value
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). Unlike the assert_type() macro, this macro allows a constant value
> + * as the second argument. And if the second argument is a constant value, it
> + * always passes. And it doesn't mean that the types are explicitly the same.
> + * When a constant value is used as the second argument, if you need an
> + * overflow check when assigning a constant value to a variable of the type of
> + * the first argument, you can use the overflows_type() macro. When a constant
> + * value is not used as a second argument, it determines whether the first
> + * argument's data type and the second argument's data type are the same while
> + * compiling, and it breaks compile if the two types are not the same.
> + * See also assert_type() and overflows_type().
> + */
> +#define assert_typable(t, n) _Static_assert(__builtin_constant_p(n) ||	\
> +					    __same_type(t, typeof(n)))
> +
>  /*
>   * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
>   *			       non-scalar types unchanged.
> -- 
> 2.37.1

WARNING: multiple messages have this Message-ID (diff)
From: Andi Shyti <andi.shyti@linux.intel.com>
To: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, mchehab@kernel.org,
	chris@chris-wilson.co.uk, matthew.auld@intel.com,
	thomas.hellstrom@linux.intel.com, jani.nikula@intel.com,
	nirmoy.das@intel.com, airlied@redhat.com, daniel@ffwll.ch,
	andi.shyti@linux.intel.com, andrzej.hajda@intel.com,
	keescook@chromium.org, mauro.chehab@linux.intel.com,
	linux@rasmusvillemoes.dk, vitor@massaru.org, dlatypov@google.com,
	ndesaulniers@google.com
Subject: Re: [PATCH v10 3/9] compiler_types.h: Add assert_type to catch type mis-match while compiling
Date: Sun, 11 Sep 2022 13:04:55 +0200	[thread overview]
Message-ID: <Yx3A16ZElKOeJr0o@alfio.lan> (raw)
In-Reply-To: <20220909105913.752049-4-gwan-gyeong.mun@intel.com>

Hi Gwan-gyeong,

On Fri, Sep 09, 2022 at 07:59:07PM +0900, Gwan-gyeong Mun wrote:
> It adds assert_type and assert_typable macros to catch type mis-match while

/Add/It adds/, please use the imperative form.

> compiling. The existing typecheck() macro outputs build warnings, but the
> newly added assert_type() macro uses the _Static_assert() keyword (which is
> introduced in C11) to generate a build break when the types are different
> and can be used to detect explicit build errors.
> Unlike the assert_type() macro, assert_typable() macro allows a constant
> value as the second argument.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Kees Cook <keescook@chromium.org>
> ---
>  include/linux/compiler_types.h | 39 ++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index 4f2a819fd60a..19cc125918bb 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -294,6 +294,45 @@ struct ftrace_likely_data {
>  /* Are two types/vars the same type (ignoring qualifiers)? */
>  #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
>  
> +/**
> + * assert_type - break compile if the first argument's data type and the second
> + *               argument's data type are not the same

I would use /aborts compilation/break compile/

> + *

nowhere is written that this extra blank line is not needed, but
just checking the style in compiler_types.h it is not used.

I personally like the blank line, but standing to the general
taste, it should be removed also for keeping a coherent style.

> + * @t1: data type or variable
> + * @t2: data type or variable
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). It determines whether the first argument's data type and the second
> + * argument's data type are the same while compiling, and it breaks compile if
> + * the two types are not the same.
> + * See also assert_typable().
> + */
> +#define assert_type(t1, t2) _Static_assert(__same_type(t1, t2))

In C11 _Static_assert is defined as:

  _Static_assert ( constant-expression , string-literal ) ;

While

  _Static_assert ( constant-expression ) ;

is defined in C17 along with the previous. I think you should add
the error message as a 'string-literal'.

Andi

> +/**
> + * assert_typable - break compile if the first argument's data type and the
> + *                  second argument's data type are not the same
> + *
> + * @t: data type or variable
> + * @n: data type or variable or constant value
> + *
> + * The first and second arguments can be data types or variables or mixed (the
> + * first argument is the data type and the second argument is variable or vice
> + * versa). Unlike the assert_type() macro, this macro allows a constant value
> + * as the second argument. And if the second argument is a constant value, it
> + * always passes. And it doesn't mean that the types are explicitly the same.
> + * When a constant value is used as the second argument, if you need an
> + * overflow check when assigning a constant value to a variable of the type of
> + * the first argument, you can use the overflows_type() macro. When a constant
> + * value is not used as a second argument, it determines whether the first
> + * argument's data type and the second argument's data type are the same while
> + * compiling, and it breaks compile if the two types are not the same.
> + * See also assert_type() and overflows_type().
> + */
> +#define assert_typable(t, n) _Static_assert(__builtin_constant_p(n) ||	\
> +					    __same_type(t, typeof(n)))
> +
>  /*
>   * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
>   *			       non-scalar types unchanged.
> -- 
> 2.37.1

  reply	other threads:[~2022-09-11 11:05 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09 10:59 [Intel-gfx] [PATCH v10 0/9] Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation Gwan-gyeong Mun
2022-09-09 10:59 ` Gwan-gyeong Mun
2022-09-09 10:59 ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 1/9] overflow: Allow mixed type arguments Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-11 10:31   ` [Intel-gfx] " Andi Shyti
2022-09-11 10:31     ` Andi Shyti
2022-09-11 10:31     ` Andi Shyti
2022-09-12  8:38   ` [Intel-gfx] " Andrzej Hajda
2022-09-12  8:38     ` Andrzej Hajda
2022-09-12  8:38     ` Andrzej Hajda
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 2/9] overflow: Move and add few utility macros into overflow Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-13 11:53   ` [Intel-gfx] " Kees Cook
2022-09-13 11:53     ` Kees Cook
2022-09-13 11:53     ` Kees Cook
2022-09-17 23:31   ` [Intel-gfx] " kernel test robot
2022-09-17 23:31     ` kernel test robot
2022-09-17 23:31     ` kernel test robot
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 3/9] compiler_types.h: Add assert_type to catch type mis-match while compiling Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-11 11:04   ` Andi Shyti [this message]
2022-09-11 11:04     ` Andi Shyti
2022-09-11 11:04     ` Andi Shyti
2022-09-12  9:52     ` [Intel-gfx] " Rasmus Villemoes
2022-09-12  9:52       ` Rasmus Villemoes
2022-09-12  9:52       ` Rasmus Villemoes
2022-09-12 10:21       ` [Intel-gfx] " Andi Shyti
2022-09-12 10:21         ` Andi Shyti
2022-09-12 10:21         ` Andi Shyti
2022-09-13 12:01   ` [Intel-gfx] " Kees Cook
2022-09-13 12:01     ` Kees Cook
2022-09-13 12:01     ` Kees Cook
2022-09-21 14:10     ` [Intel-gfx] " Gwan-gyeong Mun
2022-09-21 14:10       ` Gwan-gyeong Mun
2022-09-21 14:10       ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 4/9] drm/i915/gem: Typecheck page lookups Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-10  6:53   ` kernel test robot
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 5/9] drm/i915: Check for integer truncation on scatterlist creation Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 6/9] drm/i915: Check for integer truncation on the configuration of ttm place Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 7/9] drm/i915: Check if the size is too big while creating shmem file Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 8/9] drm/i915: Use error code as -E2BIG when the size of gem ttm object is too large Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59 ` [Intel-gfx] [PATCH v10 9/9] drm/i915: Remove truncation warning for large objects Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 10:59   ` Gwan-gyeong Mun
2022-09-09 11:24 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation Patchwork
2022-09-11 11:22 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation (rev2) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yx3A16ZElKOeJr0o@alfio.lan \
    --to=andi.shyti@linux.intel.com \
    --cc=airlied@redhat.com \
    --cc=andrzej.hajda@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel@ffwll.ch \
    --cc=dlatypov@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gwan-gyeong.mun@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=matthew.auld@intel.com \
    --cc=mchehab@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nirmoy.das@intel.com \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=vitor@massaru.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.