Re: [Intel-gfx] [PATCH V2] include: linux: Regularise the use of FIELD_SIZEOF macro
Hi Kees, Cc'ing William Kucharski, > On Wed, Jun 12, 2019 at 01:08:36AM +0530, Shyam Saini wrote: > > In favour of FIELD_SIZEOF, this patch also deprecates other two similar > > macros sizeof_field and SIZEOF_FIELD. > > > > For code compatibility reason, retain sizeof_field macro as a wrapper macro > > to FIELD_SIZEOF > > Can you explain this part? First sentence says you want to remove > sizeof_field, and the second says you're keeping it? I thought the point > was to switch all of these to FIELD_SIZEOF()? Previously, William [1] suggested to retain sizeof_field as macro to FIELD_SIZEOF for code compatibility reason. I have removed all the usage of sizeof_field apart from retained wrapper macro definition. [1] https://patchwork.ozlabs.org/patch/1085275/ Thanks, Shyam > > > > arch/arm64/include/asm/processor.h | 10 +- > > arch/mips/cavium-octeon/executive/cvmx-bootmem.c | 9 + > > 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 | 17 ++--- > > 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 | 22 > > +++--- > > virt/kvm/kvm_main.c| 2 +- > > 22 files changed, 58 insertions(+), 47 deletions(-) > > > > diff --git a/arch/arm64/include/asm/processor.h > > b/arch/arm64/include/asm/processor.h > > index fcd0e691b1ea..ace906d887cc 100644 > > --- a/arch/arm64/include/asm/processor.h > > +++ b/arch/arm64/include/asm/processor.h > > @@ -164,13 +164,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..44b506a14666 100644 > > --- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c > > +++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c > > @@ -45,13 +45,6 @@ static struct cvmx_bootmem_desc *cvmx_bootmem_desc; > > /* See header file for descriptions of functions */ > > > > /** > > - * This macro returns the size of a member of a structure. > > - * Logically it is the same as "sizeof(s::field)" in C++, but > > - * C lacks the "::" operator. > > - */ > > -#define SIZEOF_FIELD(s, field) sizeof(((s *)NULL)->field) > > - > > -/** > > * This macro returns a member of the > > * cvmx_bootmem_named_block_desc_t structure. These members can't > > * be directly addressed as they might be in memory not directly > > @@ -65,7 +58,7 @@ static struct
Re: [Intel-gfx] [PATCH V2] include: linux: Regularise the use of FIELD_SIZEOF macro
Hi Andrew, > > On Tue, 11 Jun 2019 15:00:10 -0600 Andreas Dilger wrote: > > > >> to FIELD_SIZEOF > > > > > > As Alexey has pointed out, C structs and unions don't have fields - > > > they have members. So this is an opportunity to switch everything to > > > a new member_sizeof(). > > > > > > What do people think of that and how does this impact the patch footprint? > > > > I did a check, and FIELD_SIZEOF() is used about 350x, while sizeof_field() > > is about 30x, and SIZEOF_FIELD() is only about 5x. > > Erk. Sorry, I should have grepped. > > > That said, I'm much more in favour of "sizeof_field()" or "sizeof_member()" > > than FIELD_SIZEOF(). Not only does that better match "offsetof()", with > > which it is closely related, but is also closer to the original "sizeof()". > > > > Since this is a rather trivial change, it can be split into a number of > > patches to get approval/landing via subsystem maintainers, and there is no > > huge urgency to remove the original macros until the users are gone. It > > would make sense to remove SIZEOF_FIELD() and sizeof_field() quickly so > > they don't gain more users, and the remaining FIELD_SIZEOF() users can be > > whittled away as the patches come through the maintainer trees. > > In that case I'd say let's live with FIELD_SIZEOF() and remove > sizeof_field() and SIZEOF_FIELD(). > > I'm a bit surprised that the FIELD_SIZEOF() definition ends up in > stddef.h rather than in kernel.h where such things are normally > defined. Why is that? Thanks for pointing out this, I was not aware if this is a convention. Anyway, I'll keep FIELD_SIZEOF definition in kernel.h in next version. ___ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
[Intel-gfx] [PATCH V2] include: linux: Regularise the use of FIELD_SIZEOF macro
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 In favour of FIELD_SIZEOF, this patch also deprecates other two similar macros sizeof_field and SIZEOF_FIELD. For code compatibility reason, retain sizeof_field macro as a wrapper macro to FIELD_SIZEOF Signed-off-by: Shyam Saini --- Changelog: V1->V2 - Consolidate previous patch 1 and 2 into single patch - For code compatibility reason, retain sizeof_field macro as a wrapper macro to FIELD_SIZEOF arch/arm64/include/asm/processor.h | 10 +- arch/mips/cavium-octeon/executive/cvmx-bootmem.c | 9 + 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 | 17 ++--- 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 | 22 +++--- virt/kvm/kvm_main.c| 2 +- 22 files changed, 58 insertions(+), 47 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fcd0e691b1ea..ace906d887cc 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -164,13 +164,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..44b506a14666 100644 --- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c +++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c @@ -45,13 +45,6 @@ static struct cvmx_bootmem_desc *cvmx_bootmem_desc; /* See header file for descriptions of functions */ /** - * This macro returns the size of a member of a structure. - * Logically it is the same as "sizeof(s::field)" in C++, but - * C lacks the "::" operator. - */ -#define SIZEOF_FIELD(s, field) sizeof(((s *)NULL)->field) - -/** * This macro returns a member of the * cvmx_bootmem_named_block_desc_t structure. These members can't * be directly addressed as they might be in memory not directly @@ -65,7 +58,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 0f919f0a43d4..820f95a52542 100644 --- a/drivers/gpu/drm/i915/gvt
Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro
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 2/2] include: linux: Remove unused macros and their defination
In favour of FIELD_SIZEOF, lets deprecate other two similar macros sizeof_field and SIZEOF_FIELD, and remove them completely. Signed-off-by: Shyam Saini --- arch/mips/cavium-octeon/executive/cvmx-bootmem.c | 7 --- include/linux/stddef.h | 8 tools/testing/selftests/bpf/bpf_util.h | 4 3 files changed, 19 deletions(-) diff --git a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c index fc754d155002..44b506a14666 100644 --- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c +++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c @@ -45,13 +45,6 @@ static struct cvmx_bootmem_desc *cvmx_bootmem_desc; /* See header file for descriptions of functions */ /** - * This macro returns the size of a member of a structure. - * Logically it is the same as "sizeof(s::field)" in C++, but - * C lacks the "::" operator. - */ -#define SIZEOF_FIELD(s, field) sizeof(((s *)NULL)->field) - -/** * This macro returns a member of the * cvmx_bootmem_named_block_desc_t structure. These members can't * be directly addressed as they might be in memory not directly diff --git a/include/linux/stddef.h b/include/linux/stddef.h index 63f2302bc406..b888eb7795a1 100644 --- a/include/linux/stddef.h +++ b/include/linux/stddef.h @@ -29,14 +29,6 @@ enum { #define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f)) /** - * sizeof_field(TYPE, MEMBER) - * - * @TYPE: The structure containing the field of interest - * @MEMBER: The field to return the size of - */ -#define sizeof_field(TYPE, MEMBER) sizeofTYPE *)0)->MEMBER)) - -/** * offsetofend(TYPE, MEMBER) * * @TYPE: The type of the structure diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h index 2e90a4315b55..815e7b48fa37 100644 --- a/tools/testing/selftests/bpf/bpf_util.h +++ b/tools/testing/selftests/bpf/bpf_util.h @@ -67,10 +67,6 @@ static inline unsigned int bpf_num_possible_cpus(void) */ #define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f)) -#ifndef sizeof_field -#define sizeof_field(TYPE, MEMBER) sizeofTYPE *)0)->MEMBER)) -#endif - #ifndef offsetofend #define offsetofend(TYPE, MEMBER) \ (offsetof(TYPE, MEMBER) + FIELD_SIZEOF(TYPE, MEMBER)) -- 2.11.0 ___ 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
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_fi
Re: [Intel-gfx] [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro
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