Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

2019-04-20 Thread Shyam Saini
Hi William,

Sorry for the late reply.

> > Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
> > and FIELD_SIZEOF which are used to calculate the size of a member of
> > structure, so to bring uniformity in entire kernel source tree lets use
> > FIELD_SIZEOF and replace all occurrences of other two macros with this.
> >
> > For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
> > tools/testing/selftests/bpf/bpf_util.h and remove its defination from
> > include/linux/kernel.h
>
>
> > --- a/include/linux/stddef.h
> > +++ b/include/linux/stddef.h
> > @@ -20,6 +20,15 @@ enum {
> > #endif
> >
> > /**
> > + * FIELD_SIZEOF - get the size of a struct's field
> > + * @t: the target struct
> > + * @f: the target struct's field
> > + * Return: the size of @f in the struct definition without having a
> > + * declared instance of @t.
> > + */
> > +#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
> > +
> > +/**
> >  * sizeof_field(TYPE, MEMBER)
> >  *
> >  * @TYPE: The structure containing the field of interest
> > @@ -34,6 +43,6 @@ enum {
> >  * @MEMBER: The member within the structure to get the end offset of
> >  */
> > #define offsetofend(TYPE, MEMBER) \
> > - (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
> > + (offsetof(TYPE, MEMBER) + FIELD_SIZEOF(TYPE, MEMBER))
>
> If you're doing this, why are you leaving the definition of sizeof_field() in
> stddef.h untouched?

I have removed definition of sizeof_field in [1/2] patch.

> Given the way this has worked historically, if you are leaving it in place for
> source compatibility reasons, shouldn't it be redefined in terms of
> FIELD_SIZEOF(), e.g.:
>
> #define sizeof_field(TYPE, MEMBER) FIELD_SIZEOF(TYPE, MEMBER)

Actually, never thought this way. So,Thanks a lot for this valuable feedback.

I'll re-spin and post again.
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

2019-04-15 Thread Shyam Saini
Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
and FIELD_SIZEOF which are used to calculate the size of a member of
structure, so to bring uniformity in entire kernel source tree lets use
FIELD_SIZEOF and replace all occurrences of other two macros with this.

For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
tools/testing/selftests/bpf/bpf_util.h and remove its defination from
include/linux/kernel.h

Signed-off-by: Shyam Saini 
---
 arch/arm64/include/asm/processor.h | 10 +-
 arch/mips/cavium-octeon/executive/cvmx-bootmem.c   |  2 +-
 drivers/gpu/drm/i915/gvt/scheduler.c   |  2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c |  4 ++--
 fs/befs/linuxvfs.c |  2 +-
 fs/ext2/super.c|  2 +-
 fs/ext4/super.c|  2 +-
 fs/freevxfs/vxfs_super.c   |  2 +-
 fs/orangefs/super.c|  2 +-
 fs/ufs/super.c |  2 +-
 include/linux/kernel.h |  9 -
 include/linux/slab.h   |  2 +-
 include/linux/stddef.h | 11 ++-
 kernel/fork.c  |  2 +-
 kernel/utsname.c   |  2 +-
 net/caif/caif_socket.c |  2 +-
 net/core/skbuff.c  |  2 +-
 net/ipv4/raw.c |  2 +-
 net/ipv6/raw.c |  2 +-
 net/sctp/socket.c  |  4 ++--
 tools/testing/selftests/bpf/bpf_util.h | 11 ++-
 virt/kvm/kvm_main.c|  2 +-
 22 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/arch/arm64/include/asm/processor.h 
b/arch/arm64/include/asm/processor.h
index 5d9ce62bdebd..79141eb2c673 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -156,13 +156,13 @@ static inline void arch_thread_struct_whitelist(unsigned 
long *offset,
unsigned long *size)
 {
/* Verify that there is no padding among the whitelisted fields: */
-   BUILD_BUG_ON(sizeof_field(struct thread_struct, uw) !=
-sizeof_field(struct thread_struct, uw.tp_value) +
-sizeof_field(struct thread_struct, uw.tp2_value) +
-sizeof_field(struct thread_struct, uw.fpsimd_state));
+   BUILD_BUG_ON(FIELD_SIZEOF(struct thread_struct, uw) !=
+FIELD_SIZEOF(struct thread_struct, uw.tp_value) +
+FIELD_SIZEOF(struct thread_struct, uw.tp2_value) +
+FIELD_SIZEOF(struct thread_struct, uw.fpsimd_state));
 
*offset = offsetof(struct thread_struct, uw);
-   *size = sizeof_field(struct thread_struct, uw);
+   *size = FIELD_SIZEOF(struct thread_struct, uw);
 }
 
 #ifdef CONFIG_COMPAT
diff --git a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c 
b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
index ba8f82a29a81..fc754d155002 100644
--- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
+++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
@@ -65,7 +65,7 @@ static struct cvmx_bootmem_desc *cvmx_bootmem_desc;
 #define CVMX_BOOTMEM_NAMED_GET_FIELD(addr, field)  \
__cvmx_bootmem_desc_get(addr,   \
offsetof(struct cvmx_bootmem_named_block_desc, field),  \
-   SIZEOF_FIELD(struct cvmx_bootmem_named_block_desc, field))
+   FIELD_SIZEOF(struct cvmx_bootmem_named_block_desc, field))
 
 /**
  * This function is the implementation of the get macros defined
diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c 
b/drivers/gpu/drm/i915/gvt/scheduler.c
index 05b953793316..6b344ff7c1f8 100644
--- a/drivers/gpu/drm/i915/gvt/scheduler.c
+++ b/drivers/gpu/drm/i915/gvt/scheduler.c
@@ -1206,7 +1206,7 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)
  sizeof(struct 
intel_vgpu_workload), 0,
  SLAB_HWCACHE_ALIGN,
  offsetof(struct 
intel_vgpu_workload, rb_tail),
- sizeof_field(struct 
intel_vgpu_workload, rb_tail),
+ FIELD_SIZEOF(struct 
intel_vgpu_workload, rb_tail),
  NULL);
 
if (!s->workloads) {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
index 46baf3b44309..c0447bf07fbb 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c

Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

2019-04-15 Thread William Kucharski


> On Apr 14, 2019, at 3:14 AM, Shyam Saini  
> wrote:
> 
> Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
> and FIELD_SIZEOF which are used to calculate the size of a member of
> structure, so to bring uniformity in entire kernel source tree lets use
> FIELD_SIZEOF and replace all occurrences of other two macros with this.
> 
> For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
> tools/testing/selftests/bpf/bpf_util.h and remove its defination from
> include/linux/kernel.h


> --- a/include/linux/stddef.h
> +++ b/include/linux/stddef.h
> @@ -20,6 +20,15 @@ enum {
> #endif
> 
> /**
> + * FIELD_SIZEOF - get the size of a struct's field
> + * @t: the target struct
> + * @f: the target struct's field
> + * Return: the size of @f in the struct definition without having a
> + * declared instance of @t.
> + */
> +#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
> +
> +/**
>  * sizeof_field(TYPE, MEMBER)
>  *
>  * @TYPE: The structure containing the field of interest
> @@ -34,6 +43,6 @@ enum {
>  * @MEMBER: The member within the structure to get the end offset of
>  */
> #define offsetofend(TYPE, MEMBER) \
> - (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
> + (offsetof(TYPE, MEMBER) + FIELD_SIZEOF(TYPE, MEMBER))

If you're doing this, why are you leaving the definition of sizeof_field() in
stddef.h untouched?

Given the way this has worked historically, if you are leaving it in place for
source compatibility reasons, shouldn't it be redefined in terms of
FIELD_SIZEOF(), e.g.:

#define sizeof_field(TYPE, MEMBER) FIELD_SIZEOF(TYPE, MEMBER)



___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

2019-04-15 Thread Alexei Starovoitov
On Sun, Apr 14, 2019 at 2:15 AM Shyam Saini
 wrote:
>
> Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
> and FIELD_SIZEOF which are used to calculate the size of a member of
> structure, so to bring uniformity in entire kernel source tree lets use
> FIELD_SIZEOF and replace all occurrences of other two macros with this.
>
> For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
> tools/testing/selftests/bpf/bpf_util.h and remove its defination from
> include/linux/kernel.h
>
> Signed-off-by: Shyam Saini 
> ---
>  arch/arm64/include/asm/processor.h | 10 +-
>  arch/mips/cavium-octeon/executive/cvmx-bootmem.c   |  2 +-
>  drivers/gpu/drm/i915/gvt/scheduler.c   |  2 +-
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c |  4 ++--
>  fs/befs/linuxvfs.c |  2 +-
>  fs/ext2/super.c|  2 +-
>  fs/ext4/super.c|  2 +-
>  fs/freevxfs/vxfs_super.c   |  2 +-
>  fs/orangefs/super.c|  2 +-
>  fs/ufs/super.c |  2 +-
>  include/linux/kernel.h |  9 -
>  include/linux/slab.h   |  2 +-
>  include/linux/stddef.h | 11 ++-
>  kernel/fork.c  |  2 +-
>  kernel/utsname.c   |  2 +-
>  net/caif/caif_socket.c |  2 +-
>  net/core/skbuff.c  |  2 +-
>  net/ipv4/raw.c |  2 +-
>  net/ipv6/raw.c |  2 +-
>  net/sctp/socket.c  |  4 ++--
>  tools/testing/selftests/bpf/bpf_util.h | 11 ++-

tools/ directory is for user space pieces that don't include kernel's include.
I bet your pathes break the user space builds.
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

2019-04-15 Thread Shyam Saini
Hi,

On Mon, Apr 15, 2019 at 11:13 AM Alexei Starovoitov
 wrote:
>
> On Sun, Apr 14, 2019 at 2:15 AM Shyam Saini
>  wrote:
> >
> > Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
> > and FIELD_SIZEOF which are used to calculate the size of a member of
> > structure, so to bring uniformity in entire kernel source tree lets use
> > FIELD_SIZEOF and replace all occurrences of other two macros with this.
> >
> > For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
> > tools/testing/selftests/bpf/bpf_util.h and remove its defination from
> > include/linux/kernel.h
> >
> > Signed-off-by: Shyam Saini 
> > ---
> >  arch/arm64/include/asm/processor.h | 10 +-
> >  arch/mips/cavium-octeon/executive/cvmx-bootmem.c   |  2 +-
> >  drivers/gpu/drm/i915/gvt/scheduler.c   |  2 +-
> >  drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c |  4 ++--
> >  fs/befs/linuxvfs.c |  2 +-
> >  fs/ext2/super.c|  2 +-
> >  fs/ext4/super.c|  2 +-
> >  fs/freevxfs/vxfs_super.c   |  2 +-
> >  fs/orangefs/super.c|  2 +-
> >  fs/ufs/super.c |  2 +-
> >  include/linux/kernel.h |  9 -
> >  include/linux/slab.h   |  2 +-
> >  include/linux/stddef.h | 11 ++-
> >  kernel/fork.c  |  2 +-
> >  kernel/utsname.c   |  2 +-
> >  net/caif/caif_socket.c |  2 +-
> >  net/core/skbuff.c  |  2 +-
> >  net/ipv4/raw.c |  2 +-
> >  net/ipv6/raw.c |  2 +-
> >  net/sctp/socket.c  |  4 ++--
> >  tools/testing/selftests/bpf/bpf_util.h | 11 ++-
>
> tools/ directory is for user space pieces that don't include kernel's include.
> I bet your pathes break the user space builds.

I think it shouldn't because I haven't included any kernel header in
tool/ files, instead
I have introduced definition of macro in tool/ , so this patch doesn't
create any dependency
on kernel headers.

Thanks a lot,
Shyam
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx