* Please remove all bit fields in bpf uapi
@ 2020-12-18 8:52 Meng Zhuo
2020-12-18 8:56 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Meng Zhuo @ 2020-12-18 8:52 UTC (permalink / raw)
To: linux-api; +Cc: bpf
Hi, all
I'm tring to port bpf.h to Go, however it's very hard to make it right
with cgo since bit fields some fields didn't match any type of Go.
i.e.
struct bpf_prog_info {
/* .... */
__u32 gpl_compatible:1; <-- boolean ?
__u32 :31; /* alignment pad */ <--- padding with 31 ?
UAPI(User application interface) not just for GCC only right? If it's
true, I think remove all bit fields is more appropriate.
Thanks. Regards
Meng Zhuo
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Please remove all bit fields in bpf uapi 2020-12-18 8:52 Please remove all bit fields in bpf uapi Meng Zhuo @ 2020-12-18 8:56 ` Greg KH 2020-12-18 9:09 ` Meng Zhuo 0 siblings, 1 reply; 6+ messages in thread From: Greg KH @ 2020-12-18 8:56 UTC (permalink / raw) To: Meng Zhuo; +Cc: linux-api, bpf On Fri, Dec 18, 2020 at 04:52:15PM +0800, Meng Zhuo wrote: > Hi, all > > I'm tring to port bpf.h to Go, however it's very hard to make it right > with cgo since bit fields some fields didn't match any type of Go. > > i.e. > struct bpf_prog_info { > /* .... */ > __u32 gpl_compatible:1; <-- boolean ? > __u32 :31; /* alignment pad */ <--- padding with 31 ? > > UAPI(User application interface) not just for GCC only right? If it's > true, I think remove all bit fields is more appropriate. It's a bit late to change a user-visable api, sorry. Go has to have some way of properly handling bit fields, this isn't a new thing :) good luck! greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Please remove all bit fields in bpf uapi 2020-12-18 8:56 ` Greg KH @ 2020-12-18 9:09 ` Meng Zhuo 2020-12-18 10:31 ` Greg KH 0 siblings, 1 reply; 6+ messages in thread From: Meng Zhuo @ 2020-12-18 9:09 UTC (permalink / raw) To: Greg KH; +Cc: linux-api, bpf Hi, Greg Thank you for your reply It's fine to do compile bit fields "by hand". However is it possible to setup a guideline that forrbid "bit fields" in uapi in the future? Thanks Greg KH <gregkh@linuxfoundation.org> 于2020年12月18日周五 下午4:57写道: > > On Fri, Dec 18, 2020 at 04:52:15PM +0800, Meng Zhuo wrote: > > Hi, all > > > > I'm tring to port bpf.h to Go, however it's very hard to make it right > > with cgo since bit fields some fields didn't match any type of Go. > > > > i.e. > > struct bpf_prog_info { > > /* .... */ > > __u32 gpl_compatible:1; <-- boolean ? > > __u32 :31; /* alignment pad */ <--- padding with 31 ? > > > > UAPI(User application interface) not just for GCC only right? If it's > > true, I think remove all bit fields is more appropriate. > > It's a bit late to change a user-visable api, sorry. Go has to have > some way of properly handling bit fields, this isn't a new thing :) > > good luck! > > greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Please remove all bit fields in bpf uapi 2020-12-18 9:09 ` Meng Zhuo @ 2020-12-18 10:31 ` Greg KH 2020-12-18 11:04 ` Florian Weimer 0 siblings, 1 reply; 6+ messages in thread From: Greg KH @ 2020-12-18 10:31 UTC (permalink / raw) To: Meng Zhuo; +Cc: linux-api, bpf On Fri, Dec 18, 2020 at 05:09:58PM +0800, Meng Zhuo wrote: > Hi, Greg > > Thank you for your reply > It's fine to do compile bit fields "by hand". Surely Go has something like "if (field & 0x01)", right? That's all you need for a bitfield. Look at the most common syscall, open(2)? It uses bitfields, why can't Go handle that? > However is it possible to setup a guideline that forrbid "bit fields" > in uapi in the future? Where would that guideline go and who would enforce it? :) thanks, greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Please remove all bit fields in bpf uapi 2020-12-18 10:31 ` Greg KH @ 2020-12-18 11:04 ` Florian Weimer 2020-12-18 13:05 ` Daniel Borkmann 0 siblings, 1 reply; 6+ messages in thread From: Florian Weimer @ 2020-12-18 11:04 UTC (permalink / raw) To: Greg KH; +Cc: Meng Zhuo, linux-api, bpf * Greg KH: > On Fri, Dec 18, 2020 at 05:09:58PM +0800, Meng Zhuo wrote: >> Hi, Greg >> >> Thank you for your reply >> It's fine to do compile bit fields "by hand". > > Surely Go has something like "if (field & 0x01)", right? That's all you > need for a bitfield. > > Look at the most common syscall, open(2)? It uses bitfields, why > can't Go handle that? Flag arguments are very different from bit-fields in struct types. Structs with bit-fields are not part of the highly portable C subset. Even C compilers differ in their interpretation. Thanks, Florian -- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Please remove all bit fields in bpf uapi 2020-12-18 11:04 ` Florian Weimer @ 2020-12-18 13:05 ` Daniel Borkmann 0 siblings, 0 replies; 6+ messages in thread From: Daniel Borkmann @ 2020-12-18 13:05 UTC (permalink / raw) To: Florian Weimer, Greg KH; +Cc: Meng Zhuo, linux-api, bpf On 12/18/20 12:04 PM, Florian Weimer wrote: >> On Fri, Dec 18, 2020 at 05:09:58PM +0800, Meng Zhuo wrote: >>> Hi, Greg >>> >>> Thank you for your reply >>> It's fine to do compile bit fields "by hand". >> >> Surely Go has something like "if (field & 0x01)", right? That's all you >> need for a bitfield. >> >> Look at the most common syscall, open(2)? It uses bitfields, why >> can't Go handle that? > > Flag arguments are very different from bit-fields in struct types. > > Structs with bit-fields are not part of the highly portable C subset. > Even C compilers differ in their interpretation. Bitfields are still quite common though, not special to BPF in any way ... how do you deal with all these cases then? git grep -P -n "[a-z]+:[1-9]+" include/uapi/ | wc -l 272 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-12-18 13:06 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-18 8:52 Please remove all bit fields in bpf uapi Meng Zhuo 2020-12-18 8:56 ` Greg KH 2020-12-18 9:09 ` Meng Zhuo 2020-12-18 10:31 ` Greg KH 2020-12-18 11:04 ` Florian Weimer 2020-12-18 13:05 ` Daniel Borkmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox