Best userspace programming API for XDP features query to kernel?
Daniel Borkmann
On 04/05/2018 10:51 PM, Jesper Dangaard Brouer wrote:
On Thu, 5 Apr 2018 12:37:19 +0200Sure, that was perfectly clear. (But at the same time if you extend the ioctl, it's obvious to also add support to actual ethtool cmdline tool.) [2] https://github.com/OISF/suricata/blob/master/src/util-ioctl.c#L326Not really, that's the front end. ndo_bpf itself is a plain netdev op and has no real tie to netlink. want drivers to call their own ndo_bpf, when activated though theirWhat I was saying is that even if you go via ethtool ioctl api, where you end up in dev_ethtool() and have some new ETHTOOL_* query command, then instead of adding a new ethtool_ops callback, we can and should reuse ndo_bpf from there. [...] Here, I want to discuss how drivers expose/tell userspace that theyOk, so with the example of meta data, you're arguing that it's okay to load a native XDP program onto a driver, and run actual traffic on the NIC in order probe for the availability of the feature when you're saying that it "can detect/see [at] runtime". I totally agree with you that all drivers should eventually support this (same with XDP_REDIRECT), but today there are even differences in drivers on bpf_xdp_adjust_meta()/ bpf_xdp_adjust_head() with regards to how much headroom they have available, etc (e.g. some of them have none), so right now you can either go and read the code or do a runtime test with running actual traffic through the NIC to check whether your BPF prog is supported or not. Theoretically, you can do the same runtime test with XDP_REDIRECT (taking the warn in bpf_warn_invalid_xdp_action() aside for a moment), but you do have the trace_xdp_exception() tracepoint to figure it out, yes, it's a painful hassle, but overall, it's not that different as you were trying to argue here. For /both/ cases it would be nice to know at setup time whether this would be supported or not. Hence, such query is not just limited to XDP_REDIRECT alone. Eventually once such interface is agreed upon, undoubtedly the list of feature bits will grow is what I'm trying to say; only arguing on the XDP_REDIRECT here would be short term. [...] Yep, agree it's not pretty, not claiming any of this is. You kind ofWhat about keeping this high level to users? E.g. say you have 2 optionsI use-to-be, an advocate for this. I even think I send patches need to be aware of the underlying kernel, similar to the tracing case. The underlying problem is effectively the decoupling of program verification that doesn't have/know the context of where it is being attached to in this case. Thinking out loud for a sec on couple of other options aside from feature bits, what about i) providing the target ifindex to the verifier for XDP programs, such that at verification time you have the full context similar to nfp offload case today, or ii) populating some XDP specific auxillary data to the BPF program at verification time such that the driver can check at program attach time whether the requested features are possible and if not it will reject and respond with netlink extack message to the user (as we do in various XDP attach cases already through XDP_SETUP_PROG{,_HW}). This would, for example, avoid the need for feature bits, and do actual rejection of the program while retaining flexibility (and avoiding to expose bits that over time hopefully will deprecate anyway due to all XDP aware drivers implementing them). For both cases i) and ii), it would mean we make the verifier a bit smarter with regards to keeping track of driver related (XDP) requirements. Program return code checking is already present in the verifier's check_return_code() and we could extend it for XDP as well, for example. Seems cleaner and more extensible than feature bits, imho. Thanks, Daniel |
|