Add support for network flow classifier
Subsystems (4)
cover Add support for network flow classifier
This series is version 5 of the patches for adding network flow classifier rules support to ethtool. The main changes are that I split a general header cleanup off into a separate patch, I combined the documentation update into the addition of the RX packet classification interface, and I generally cleaned up the code further for when we need to maintain the rule table and when we don't. As a result I dropped a few dozen lines of code related to finding and deleting a rule from the table since we only need the table to determine which rules are present.
I will be submitting a set of patches through Jeff Kirsher once these patches are accepted to allow for ixgbe to make use of the network flow classifier rules interface.
Thanks,
Alex
---
Alexander Duyck (3):
Add support for __be64 and bitops, centralize several needed macros Cleanup defines and header includes to address several issues
ethtool: remove strings based approach for displaying n-tuple
Santwona Behera (1):
v5 Add RX packet classification interface
Makefile.am | 3 ethtool-bitops.h | 25 + ethtool-util.h | 47 ++ ethtool.8.in | 194 +++++----- ethtool.c | 449 ++++++++++++----------- rxclass.c | 1039 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1433 insertions(+), 324 deletions(-) create mode 100644 ethtool-bitops.h create mode 100644 rxclass.c
PATCH 1/4 ethtool: remove strings based approach for displaying n-tuple
This change is meant to remove the strings based approach for displaying n-tuple filters. A follow-on patch will replace that functionality with a network flow classification based approach that will get the number of filters, get their locations, and then request and display them individually.
---
ethtool.c | 44 -------------------------------------------- 1 files changed, 0 insertions(+), 44 deletions(-)
ethtool.c +0 -44
@@ -3194,50 +3194,6 @@ static int do_srxntuple(int fd, struct ifreq *ifr)static int do_grxntuple (int fd,struct ifreq *ifr) { -struct ethtool_sset_info *sset_info; -struct ethtool_gstrings *strings; -int sz_str, n_strings, err, i; - - sset_info =malloc (sizeof (struct ethtool_sset_info ) +sizeof (u32)); - sset_info->cmd =ETHTOOL_GSSET_INFO ; - sset_info->sset_mask = (1ULL <<ETH_SS_NTUPLE_FILTERS ); - ifr->ifr_data = (caddr_t )sset_info; - err =send_ioctl (fd, ifr); - -if ((err <0 ) || - (!(sset_info->sset_mask & (1ULL <<ETH_SS_NTUPLE_FILTERS )))) { -perror ("Cannot get driver strings info" ); -return 100 ; - } - - n_strings = sset_info->data[0 ]; -free (sset_info); - sz_str = n_strings *ETH_GSTRING_LEN ; - - strings =calloc (1 , sz_str +sizeof (struct ethtool_gstrings )); -if (!strings) { -fprintf (stderr,"no memory available\n" ); -return 95 ; - } - - strings->cmd =ETHTOOL_GRXNTUPLE ; - strings->string_set =ETH_SS_NTUPLE_FILTERS ; - strings->len = n_strings; - ifr->ifr_data = (caddr_t ) strings; - err =send_ioctl (fd, ifr); -if (err <0 ) { -perror ("Cannot get Rx n-tuple information" ); -free (strings); -return 101 ; - } - - n_strings = strings->len; -fprintf (stdout,"Rx n-tuple filters:\n" ); -for (i =0 ; i < n_strings; i++) -fprintf (stdout,"%s" , &strings->data[i *ETH_GSTRING_LEN ]); - -free (strings); -return 0 ; }
PATCH 2/4 Cleanup defines and header includes to address several issues
In reply to Alexander DuyckThis change is meant to address several issues. First it moves the check for ethtool-config.h into ethtool-util.h the reason for this change is so that any references to ethtool-util.h outside of ethtool.c will use the correct defines for the endian types.
In addition I have pulled several headers that will be common to both ethtool.c and rxclass.c into the ethtool-util.h header file. I am also centralizing several macros that will be needed across multiple files when I implement the network flow classifier rules.
---
ethtool-util.h | 17 +++++++++++++++-- ethtool.c | 17 +---------------- 2 files changed, 16 insertions(+), 18 deletions(-)
ethtool-util.h +15 -2
@@ -3,8 +3,13 @@#ifndef ETHTOOL_UTIL_H__ #define ETHTOOL_UTIL_H__ +#ifdef HAVE_CONFIG_H +#include "ethtool-config.h" +#endif #include <sys/types.h> #include <endian.h> +#include <sys/ioctl.h> +#include <net/if.h> /* ethtool.h expects these to be defined by <linux/types.h> */ #ifndef HAVE_BE_TYPES
@@ -12,14 +17,14 @@ typedef __uint16_t __be16;typedef __uint32_t __be32 ;#endif -#include "ethtool-copy.h" -typedef unsigned long long u64 ;typedef __uint32_t u32 ;typedef __uint16_t u16 ;typedef __uint8_t u8 ;typedef __int32_t s32 ; +#include "ethtool-copy.h" +#if __BYTE_ORDER == __BIG_ENDIANstatic inline u16 cpu_to_be16 (u16 value) {
@@ -40,6 +45,14 @@ static inline u32 cpu_to_be32(u32 value) }#endif +#ifndef ARRAY_SIZE +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) +#endif + +#ifndef SIOCETHTOOL +#define SIOCETHTOOL 0x8946 +#endif +/* National Semiconductor DP83815, DP83816 */ int natsemi_dump_regs (struct ethtool_drvinfo *info,struct ethtool_regs *regs); int natsemi_dump_eeprom(struct ethtool_drvinfo *info,
ethtool.c +1 -16
@@ -21,19 +21,12 @@* * show settings for all devices */ -#ifdef HAVE_CONFIG_H -# include "ethtool-config.h" -#endif - -#include <sys/types.h> +#include "ethtool-util.h" #include <string.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/ioctl.h> #include <sys/stat.h> #include <stdio.h> #include <errno.h> -#include <net/if.h> #include <sys/utsname.h> #include <limits.h> #include <ctype.h>
@@ -43,18 +36,10 @@#include <arpa/inet.h> #include <linux/sockios.h> -#include "ethtool-util.h" - -#ifndef SIOCETHTOOL -#define SIOCETHTOOL 0x8946 -#endif #ifndef MAX_ADDR_LEN #define MAX_ADDR_LEN 32#endif -#ifndef ARRAY_SIZE -#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) -#endif #ifndef HAVE_NETIF_MSG enum {
PATCH 3/4 Add support for __be64 and bitops, centralize several needed macros
In reply to Alexander DuyckThis change is meant to add support for __be64 values and bitops to ethtool. In addition the patch pulls the SIOCETHTOOL define and the ARRAY_SIZE define into ethtool-util.h for later use by the rxclass files. These changes will be needed in order to support network flow classifier rule configuration.
---
ethtool-bitops.h | 25 +++++++++++++++++++++++++ ethtool-util.h | 16 ++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ethtool-bitops.h
ethtool-bitops.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef ETHTOOL_BITOPS_H__ +#define ETHTOOL_BITOPS_H__ + +#define BITS_PER_BYTE 8 +#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) +#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_LONG) + +static inline void set_bit (int nr,unsigned long *addr) +{ + addr[nr /BITS_PER_LONG ] |=1UL << (nr %BITS_PER_LONG ); +} + +static inline void clear_bit (int nr,unsigned long *addr) +{ + addr[nr /BITS_PER_LONG ] &= ~(1UL << (nr %BITS_PER_LONG )); +} + +static inline int test_bit (unsigned int nr,const unsigned long *addr) +{ +return !!((1UL << (nr %BITS_PER_LONG )) & + (((unsigned long *)addr)[nr /BITS_PER_LONG ])); +} + +#endif
ethtool-util.h +14 -2
@@ -15,6 +15,7 @@#ifndef HAVE_BE_TYPES typedef __uint16_t __be16 ;typedef __uint32_t __be32 ; +typedef unsigned long long __be64 ;#endif typedef unsigned long long u64 ;
@@ -28,11 +29,15 @@ typedef __int32_t s32;#if __BYTE_ORDER == __BIG_ENDIANstatic inline u16 cpu_to_be16 (u16 value) { -return value; +return value; }static inline u32 cpu_to_be32 (u32 value) { -return value; +return value; +} +static inline u64 cpu_to_be64 (u64 value) +{ +return value; }#else static inline u16 cpu_to_be16 (u16 value)
@@ -43,8 +48,15 @@ static inline u32 cpu_to_be32(u32 value) {return cpu_to_be16 (value >>16 ) | (cpu_to_be16 (value) <<16 ); } +static inline u64 cpu_to_be64 (u64 value) +{ +return cpu_to_be32 (value >>32 ) | ((u64 )cpu_to_be32 (value) <<32 ); +}#endif +#define ntohll cpu_to_be64 +#define htonll cpu_to_be64 +#ifndef ARRAY_SIZE #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))#endif
PATCH 4/4 v5 Add RX packet classification interface
In reply to Alexander DuyckFrom: Santwona Behera <[email protected]>
This patch was originally introduced as:
[PATCH 1/3] [ethtool] Add rx pkt classification interface
http://patchwork.ozlabs.org/patch/23223/
v2:
I have updated it to address a number of issues. As a result I removed the local caching of rules due to the fact that there were memory leaks in this code and the rule manager would consume over 1Mb of space for an 8K table when all that was needed was 1K in order to store which rules were active and which were not.
In addition I dropped the use of regions as there were multiple issue found including the fact that the regions were not properly expanding beyond 2 and the fact that the regions required reading all of the rules in order to correctly expand beyond 2. By dropping the regions from the rule manager it is possible to write a much cleaner interface leaving region management to be done by either the driver or by external management scripts.
v3:
The latest update to this patch now inverts the masks to match the mask types used for n-tuple. As such a network flow classifier is defined using the exact same syntax as n-tuple, and the tool will correct for the fact that NFC uses the 1's compliment of the n-tuple mask.
I also updated the ordering of new rules being added. All new rules will take the highest numbered open rule when no location is specified.
Since NFC now uses the same syntax as n-tuple I added code such that now when location is not specified the -U option will first try to add a new n-tuple rule, and if that fails with a ENOTSUPP it will then try to add the rule via the NFC interface.
Finally I split out the addition of bitops and the updates to documentation into separate patches. This makes the total patch size a bit more manageable since the addition of NFC and the merging of it with n-tuple were combined into this patch.
v4:
This change merges the ntuple and network flow classifier rules so that if we setup a rule and the device has the NTUPLE flag set we will first try to use set_rx_ntuple. If that fails with EOPNOTSUPP we then will attempt to use the network flow classifier rule insertion. This way we can support legacy configurations such as niu on kernels prior to 2.6.40 that support network flow classifier but not ntuple, but for drivers such as ixgbe we can test for ntuple first, and then network flow classifier.
This patch has also updated the output to make use of the updated network flow classifier extensions that have been accepted into the kernel.
v5:
This change merged the documentation update into this patch. In addition the documentation changes were made such that there is only one listing of the individual options and they are all listed as optional.
In addition this patch contains several fixes to address things such as the fact that we were maintaining the table logic even though we only need it for displaying all of the rules, or when adding a rule with no location specified. As such all of the logic for deleting or finding rules in the table has been removed.
---
Makefile.am | 3 ethtool-util.h | 14 + ethtool.8.in | 194 ++++++---- ethtool.c | 400 ++++++++++++---------- rxclass.c | 1039 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1384 insertions(+), 266 deletions(-) create mode 100644 rxclass.c
Makefile.am +2 -1
@@ -8,7 +8,8 @@ ethtool_SOURCES = ethtool.c ethtool-copy.h ethtool-util.h \ amd8111e.c de2104x.c e100.c e1000.c igb.c \ fec_8xx.c ibm_emac.c ixgb.c ixgbe.c natsemi.c \ pcnet32.c realtek.c tg3.c marvell.c vioc.c \ - smsc911x.c at76c50x-usb.c sfc.c stmmac.c + smsc911x.c at76c50x-usb.c sfc.c stmmac.c \ + rxclass.c dist-hook: cp $(top_srcdir)/ethtool.spec $(distdir)
ethtool-util.h +13 -1
@@ -65,6 +65,8 @@ static inline u64 cpu_to_be64(u64 value)#define SIOCETHTOOL 0x8946#endif +#define RX_CLS_LOC_UNSPEC 0xffffffffUL +/* National Semiconductor DP83815, DP83816 */ int natsemi_dump_regs (struct ethtool_drvinfo *info,struct ethtool_regs *regs); int natsemi_dump_eeprom(struct ethtool_drvinfo *info,
@@ -128,4 +130,14 @@ int sfc_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);int st_mac100_dump_regs (struct ethtool_drvinfo *info,struct ethtool_regs *regs);int st_gmac_dump_regs (struct ethtool_drvinfo *info,struct ethtool_regs *regs); -#endif + +/* Rx flow classification */ +int rxclass_parse_ruleopts (char **optstr,int opt_cnt, +struct ethtool_rx_flow_spec *fsp); +int rxclass_rule_getall (int fd,struct ifreq *ifr); +int rxclass_rule_get (int fd,struct ifreq *ifr,__u32 loc); +int rxclass_rule_ins (int fd,struct ifreq *ifr, +struct ethtool_rx_flow_spec *fsp); +int rxclass_rule_del (int fd,struct ifreq *ifr,__u32 loc); + +#endif /* ETHTOOL_UTIL_H__ */
ethtool.8.in +103 -91
267 lines not on this page · raw message
ethtool.c +227 -173
503 lines not on this page · raw message
rxclass.c new file +1039 -0
1,039 lines not on this page · raw message
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
On 05/03/2011 09:12 AM, Alexander Duyck wrote:
[...]
rxclass.c line 240
Quoted 3 lines
rxclass.c new file +3
-0+static int rmgr_add (struct ethtool_rx_flow_spec *fsp) +{ +__u32 loc = fsp->location;
Unneeded assignment. Couple lines later you assign a new value to loc.
Quoted 49 lines
rxclass.c new file +49
-0+__u32 slot_num; + +/* start at the end of the list since it is lowest priority */ + loc = rmgr.size -1 ; + +/* locate the first slot a rule can be placed in */ + slot_num = loc /BITS_PER_LONG ; + +/* +* Avoid testing individual bits by inverting the word and checking +* to see if any bits are left set, if so there are empty spots. By +* moving 1 + loc % BITS_PER_LONG we align ourselves to the last bit +* in the previous word. +* +* If loc rolls over it should be greater than or equal to rmgr.size +* and as such we know we have reached the end of the list. +*/ +if (!~(rmgr.slot[slot_num] | (~1UL << rmgr.size %BITS_PER_LONG ))) { + loc -=1 + (loc %BITS_PER_LONG ); + slot_num--; + } + +/* +* Now that we are aligned with the last bit in each long we can just +* go though and eliminate all the longs with no free bits +*/ +while (loc < rmgr.size && !~(rmgr.slot[slot_num])) { + loc -=BITS_PER_LONG ; + slot_num--; + } + +/* +* If we still are inside the range, test individual bits as one is +* likely available for our use. +*/ +while (loc < rmgr.size &&test_bit (loc, rmgr.slot)) + loc--; + +/* location found, insert rule */ +if (loc < rmgr.size) { + fsp->location = loc; +return rmgr_ins (loc); + } + +/* No space to add this rule */ +fprintf (stderr,"rmgr: Cannot find appropriate slot to insert rule\n" ); + +return -1 ; +}
[...]
Quoted 15 lines
rxclass.c new file +15
-0+int rxclass_rule_ins (int fd,struct ifreq *ifr, +struct ethtool_rx_flow_spec *fsp) +{ +struct ethtool_rxnfc nfccmd; +__u32 loc = fsp->location; +int err; + +/* +* if location is unspecified pull rules from device +* and allocate a free rule for our use +*/ +if (loc ==RX_CLS_LOC_UNSPEC ) { +/* init table of available rules */ + err =rmgr_init (fd, ifr); +if (err <0 )
rxclass.c line 453
Quoted 10 lines
rxclass.c new file +10
-0+return err; + +/* verify rule location */ + err =rmgr_add (fsp); +if (err <0 ) +return err; + +/* cleanup table and free resources */ +rmgr_cleanup (); + }
This logic where ethtool tries to select a filter slot when a user provides RX_CLS_LOC_UNSPEC does not work in general. It assumes that all slots are equal and a new filter can go into any available slot. But a device may have restrictions on where a filter may go that ethtool doesn't know. I mentioned during a previous review that for cxgb4 some filters require a slot number that is a multiple of 4. There are some other constraints as well depending on the type of filter being added. For such a device ethtool doesn't know enough to handle RX_CLS_LOC_UNSPEC correctly.
I think RX_CLS_LOC_UNSPEC should be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove the
if (loc == RX_CLS_LOC_UNSPEC)
block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 1 line · Dimitris Michailidis
On 05/03/2011 09:12 AM, Alexander Duyck wrote:
[...]
Quoted 22 lines
Quoted 22 lines
rxclass.c new file +22
-0+int rxclass_rule_ins (int fd,struct ifreq *ifr, +struct ethtool_rx_flow_spec *fsp) +{ +struct ethtool_rxnfc nfccmd; +__u32 loc = fsp->location; +int err; + +/* +* if location is unspecified pull rules from device +* and allocate a free rule for our use +*/ +if (loc ==RX_CLS_LOC_UNSPEC ) { +/* init table of available rules */ + err =rmgr_init (fd, ifr); +if (err <0 ) +return err; + +/* verify rule location */ + err =rmgr_add (fsp); +if (err <0 ) +return err; +
Quoted 8 lines
rxclass.c line 453
Quoted 3 lines
rxclass.c new file +3
-0+/* cleanup table and free resources */ +rmgr_cleanup (); + }This logic where ethtool tries to select a filter slot when a user provides
RX_CLS_LOC_UNSPECdoes not work in general. It assumes that all slots are equal and a new filter can go into any available slot. But a device may have restrictions on where a filter may go that ethtool doesn't know.
I agree. And if filter lookup is largely hash-based (as it is in Solarflare hardware) the user will also find it very difficult to specify the right location!
Quoted 5 lines
I mentioned during a previous review that for cxgb4 some filters require a slot number that is a multiple of 4. There are some other constraints as well depending on the type of filter being added. For such a device ethtool doesn't know enough to handle
RX_CLS_LOC_UNSPECcorrectly.
Quoted 7 lines
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to ethtool.h.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 34 lines · Ben Hutchings
Quoted 1 line · Dimitris Michailidis
On 05/03/2011 09:12 AM, Alexander Duyck wrote:
[...]
Quoted 22 lines
Quoted 22 lines
rxclass.c new file +22
-0+int rxclass_rule_ins (int fd,struct ifreq *ifr, +struct ethtool_rx_flow_spec *fsp) +{ +struct ethtool_rxnfc nfccmd; +__u32 loc = fsp->location; +int err; + +/* +* if location is unspecified pull rules from device +* and allocate a free rule for our use +*/ +if (loc ==RX_CLS_LOC_UNSPEC ) { +/* init table of available rules */ + err =rmgr_init (fd, ifr); +if (err<0 ) +return err; + +/* verify rule location */ + err =rmgr_add (fsp); +if (err<0 ) +return err; +Quoted 8 lines
rxclass.c line 453
Quoted 3 lines
rxclass.c new file +3
-0+/* cleanup table and free resources */ +rmgr_cleanup (); + }This logic where ethtool tries to select a filter slot when a user provides
RX_CLS_LOC_UNSPECdoes not work in general. It assumes that all slots are equal and a new filter can go into any available slot. But a device may have restrictions on where a filter may go that ethtool doesn't know.
Quoted 3 lines
I agree. And if filter lookup is largely hash-based (as it is in Solarflare hardware) the user will also find it very difficult to specify the right location!
The thing to keep in mind is that the index doesn't have to be a hardware index. In ixgbe we have a field in the hardware which is meant to just be a unique software index and that is what I am using as the location field for our filters. All the location information in the rules really provides is a logical way of tracking rules. It doesn't necessarily have to represent the physical location of the rule in hardware.
Quoted 10 lines
Quoted 10 lines
I mentioned during a previous review that for cxgb4 some filters require a slot number that is a multiple of 4. There are some other constraints as well depending on the type of filter being added. For such a device ethtool doesn't know enough to handle
RX_CLS_LOC_UNSPECcorrectly.I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)
Quoted 7 lines
Quoted 2 lines
block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.Ben.
The other thing to keep in mind with this is that it doesn't lock you into the network flow classifier configuration. If you want to be able to specify a rule without having any location information included there is always the option of ntuple which accepts almost all the same fields but doesn't include any specific location information.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 35 lines · Alexander Duyck
Quoted 34 lines · Ben Hutchings
Quoted 1 line · Dimitris Michailidis
On 05/03/2011 09:12 AM, Alexander Duyck wrote:
[...]
Quoted 30 lines
Quoted 15 lines
rxclass.c new file +15
-0+int rxclass_rule_ins (int fd,struct ifreq *ifr, +struct ethtool_rx_flow_spec *fsp) +{ +struct ethtool_rxnfc nfccmd; +__u32 loc = fsp->location; +int err; + +/* +* if location is unspecified pull rules from device +* and allocate a free rule for our use +*/ +if (loc ==RX_CLS_LOC_UNSPEC ) { +/* init table of available rules */ + err =rmgr_init (fd, ifr); +if (err<0 )rxclass.c line 453
Quoted 10 lines
rxclass.c new file +10
-0+return err; + +/* verify rule location */ + err =rmgr_add (fsp); +if (err<0 ) +return err; + +/* cleanup table and free resources */ +rmgr_cleanup (); + }This logic where ethtool tries to select a filter slot when a user provides
RX_CLS_LOC_UNSPECdoes not work in general. It assumes that all slots are equal and a new filter can go into any available slot. But a device may have restrictions on where a filter may go that ethtool doesn't know.
Quoted 5 lines
Quoted 3 lines
I agree. And if filter lookup is largely hash-based (as it is in Solarflare hardware) the user will also find it very difficult to specify the right location!
The thing to keep in mind is that the index doesn't have to be a hardware index. In ixgbe we have a field in the hardware which is meant to just be a unique software index and that is what I am using as the location field for our filters. All the location information in the rules really provides is a logical way of tracking rules. It doesn't necessarily have to represent the physical location of the rule in hardware.
I appreciate the intent but there are couple problems.
a) ethtool.h documents location as
* @location: Index of filter in hardware table
i.e., physical location. But we could change that.
b) for TCAMs physical location is important and if ethtool offers to provide only a logical index and massages the original user input to do so where will a driver get the physical location it ultimately needs? For a device with physical indices a multiple of 4 the logical index ethtool picks will very frequently be illegal as physical location. E.g., if location 1 is available ethtool will keep selecting it and the driver will need to deal with these requests without the benefit of knowing what the user really asked for.
Another problem with ethtool selecting locations is it assumes it's the sole allocator (I think there's a comment in the code pointing this out). But this isn't a valid assumption, e.g., HW RFS comes to mind as another allocator.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 8 lines · Dimitris Michailidis
Quoted 6 lines · Alexander Duyck
The thing to keep in mind is that the index doesn't have to be a hardware index. In ixgbe we have a field in the hardware which is meant to just be a unique software index and that is what I am using as the location field for our filters. All the location information in the rules really provides is a logical way of tracking rules. It doesn't necessarily have to represent the physical location of the rule in hardware.
Quoted 6 lines
I appreciate the intent but there are couple problems.
a)ethtool.hdocuments location as* @location: Index of filter in hardware table
i.e., physical location. But we could change that.
I will probably want to change that. The fact is as I recall even niu was using a hash in addition to the location index. As such it isn't really the true location in the hardware since there is a second piece to determining the actual location in hardware.
Quoted 9 lines
b) for TCAMs physical location is important and if ethtool offers to provide only a logical index and massages the original user input to do so where will a driver get the physical location it ultimately needs? For a device with physical indices a multiple of 4 the logical index ethtool picks will very frequently be illegal as physical location. E.g., if location 1 is available ethtool will keep selecting it and the driver will need to deal with these requests without the benefit of knowing what the user really asked for.
Quoted 4 lines
Another problem with ethtool selecting locations is it assumes it's the sole allocator (I think there's a comment in the code pointing this out). But this isn't a valid assumption, e.g., HW RFS comes to mind as another allocator.
The other thing to keep in mind is that this doesn't preclude the option of adding an ethtool command at some point in the future for handling the determination of filter location. The fact is all that would need to be done is to add an extra ioctl call to determine the location based on the filter and if that returns op not supported we fall back to the current rule manager.
The way I have things setup now provides a good foundation in user-space for managing the rules. I fully admit it doesn't fit all solutions, and I welcome follow-on patches to add extra functionality, but at this time I really would prefer avoiding adding extra functionality for yet to be implemented features in device drivers. The ntuple display functionality provides a good example of why I would prefer to avoid it. Everything looked like it should have worked when get_rx_ntuple was implemented in the device drivers, but as soon as I implemented a get_rx_ntuple for ixgbe I quickly discovered it didn't work and as such I am now stuck moving everything over to network flow classifier for ixgbe.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
In reply to Ben HutchingsQuoted 9 lines · Ben Hutchings
Quoted 5 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.
In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +6 -1
@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available */ struct ethtool_rx_flow_spec {__u32 flow_type;
@@ -1142,6 +1143,10 @@ struct ethtool_ops {#define RX_CLS_FLOW_DISC 0xffffffffffffffffULL +/* special values for ethtool_rx_flow_spec.location */ +#define RX_CLS_FLOW_FIRST_LOC 0xffffffffU; +#define RX_CLS_FLOW_LAST_LOC 0xfffffffeU; +/* Reset flags */ /* The reset() operation must clear the flags for the components which * were actually reset. On successful return, the flags indicate the
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 21 lines · Dimitris Michailidis
Quoted 11 lines · Ben Hutchings
Quoted 7 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +0
-0
include/linux/ethtool.h struct ethtool_flow_ext { · line 446
Quoted 6 lines
include/linux/ethtool.h +2
-1@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available
[...]
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 25 lines · Ben Hutchings
Quoted 22 lines · Dimitris Michailidis
Quoted 8 lines · Ben Hutchings
Quoted 5 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +2
-1@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available [...]
Quoted 3 lines
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Easy and true for a TCAM. For hashing would you use the location to decide how to order filters that fall in the same bucket?
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 29 lines · Dimitris Michailidis
Quoted 28 lines · Ben Hutchings
Quoted 25 lines · Dimitris Michailidis
Quoted 10 lines · Ben Hutchings
Quoted 7 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +2
-1@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available [...]
Quoted 7 lines
Quoted 3 lines
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Easy and true for a TCAM. For hashing would you use the location to decide how to order filters that fall in the same bucket?
The problem is none of this is backwards compatible. The niu driver has supported the network flow classifier rules since 2.6.30. Adding this would cause all rule setups for niu to fail because these locations would have to exist outside of the current rule locations.
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location. We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 34 lines · Alexander Duyck
Quoted 33 lines · Dimitris Michailidis
Quoted 31 lines · Ben Hutchings
Quoted 19 lines · Dimitris Michailidis
Quoted 10 lines · Ben Hutchings
Quoted 7 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +0
-0include/linux/ethtool.h struct ethtool_flow_ext { · line 446
Quoted 6 lines
include/linux/ethtool.h +2
-1@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available [...]
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Quoted 8 lines
Quoted 3 lines
Easy and true for a TCAM. For hashing would you use the location to decide how to order filters that fall in the same bucket?
The problem is none of this is backwards compatible. The niu driver has supported the network flow classifier rules since 2.6.30. Adding this would cause all rule setups for niu to fail because these locations would have to exist outside of the current rule locations.
Those rule setups would have to be using some unofficial patched ethtool. I don't think that should be a major concern for us. However...
Quoted 7 lines
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location.
We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
How about having ETHTOOL_GRXCLSRLCNT set a flag in the 'data' field to indicate that the driver can assign locations? (We would have to specify that for compatibility with older kernels the application must initialise this filed to 0.)
rmgr_init() would then check for this flag.
I hope someone is actually going to test this on niu, as it sounds like that will be the only driver using a TCAM... David?
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 39 lines · Ben Hutchings
Quoted 38 lines · Alexander Duyck
Quoted 36 lines · Dimitris Michailidis
Quoted 28 lines · Ben Hutchings
Quoted 25 lines · Dimitris Michailidis
Quoted 10 lines · Ben Hutchings
Quoted 7 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +2
-1@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC * if packets should be discarded -* @location: Index of filter in hardware table +* @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for +* first available index, or %RX_CLS_FLOW_LAST_LOC for last available [...]
Quoted 3 lines
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Easy and true for a TCAM. For hashing would you use the location to decide how to order filters that fall in the same bucket?
Quoted 8 lines
Quoted 4 lines
The problem is none of this is backwards compatible. The niu driver has supported the network flow classifier rules since 2.6.30. Adding this would cause all rule setups for niu to fail because these locations would have to exist outside of the current rule locations.
Those rule setups would have to be using some unofficial patched ethtool. I don't think that should be a major concern for us. However...
No, what I am saying is that if we were to add those locations to the ETHTOOL_SRXCLSRLINS then niu would not work anymore as it would treat them as invalid locations. This existing setup will at least work with the existing niu from what I can tell. If we were to try adding rules with locations outside of actual allowable rules then we would likely receive an indication that we provided an invalid argument.
Quoted 13 lines
Quoted 7 lines
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location.
We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
How about having
ETHTOOL_GRXCLSRLCNTset a flag in the 'data' field to indicate that the driver can assign locations? (We would have to specify that for compatibility with older kernels the application must initialise this filed to 0.)
Quoted 7 lines
rmgr_init()would then check for this flag.I hope someone is actually going to test this on niu, as it sounds like that will be the only driver using a TCAM... David?
Ben.
Honestly what I would prefer to see is a seperate call added such as an ETHTOOL_GRSCLSRLLOC that we could pass the flow specifier to and perhaps include first/last location call in that and then let the driver return where it wants to drop the rule. That way we can avoid having to create an overly complicated rule manager that can handle all the bizarre rule ordering options that I am sure all the different network devices support.
The only reason I am not implementing this now is because there aren't any drivers in place that would currently use it. I figure once cxgb has a means in place of supporting flow classifier rules then Dimitris can add the necessary code to ethtool and the kernel to allow the driver to specify rule locations. I would prefer to avoid adding features based on speculation of what will be needed and would like to be able to actually see how the features will be used.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
On Wed, 2011-05-04 at 11:21 -0700, Alexander Duyck wrote:
[...]
Quoted 4 lines
Honestly what I would prefer to see is a seperate call added such as an
ETHTOOL_GRSCLSRLLOCthat we could pass the flow specifier to and perhaps include first/last location call in that and then let the driver return where it wants to drop the rule.
This must not be done as a separate operation because it's racy (in fact that's an inherent problem with the rule manager). In the sfc driver (and probably others in future) filters could be inserted for RFS at any time.
Quoted 3 lines
That way we can avoid having to create
an overly complicated rule manager that can handle all the bizarre rule ordering options that I am sure all the different network devices support.
Right, the rule manager can't implement that.
Quoted 7 lines
The only reason I am not implementing this now is because there aren't any drivers in place that would currently use it. I figure once cxgb has a means in place of supporting flow classifier rules then Dimitris can add the necessary code to ethtool and the kernel to allow the driver to specify rule locations. I would prefer to avoid adding features based on speculation of what will be needed and would like to be able to actually see how the features will be used.
If you are going to implement the same interface in ixgbe as in niu (modulo bugs), then I have no objection to going ahead with this and then adding the option for driver-assigned locations later.
Please can you confirm that the location specified for ETHTOOL_SRXCLSRLINS will indeed be used as a priority in case of overlapping filters?
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 30 lines · Ben Hutchings
On Wed, 2011-05-04 at 11:21 -0700, Alexander Duyck wrote:
[...]Quoted 4 lines
Honestly what I would prefer to see is a seperate call added such as an
ETHTOOL_GRSCLSRLLOCthat we could pass the flow specifier to and perhaps include first/last location call in that and then let the driver return where it wants to drop the rule.This must not be done as a separate operation because it's racy (in fact that's an inherent problem with the rule manager). In the sfc driver (and probably others in future) filters could be inserted for RFS at any time.
Quoted 3 lines
That way we can avoid having to create
an overly complicated rule manager that can handle all the bizarre rule ordering options that I am sure all the different network devices support.Right, the rule manager can't implement that.
Quoted 7 lines
The only reason I am not implementing this now is because there aren't any drivers in place that would currently use it. I figure once cxgb has a means in place of supporting flow classifier rules then Dimitris can add the necessary code to ethtool and the kernel to allow the driver to specify rule locations. I would prefer to avoid adding features based on speculation of what will be needed and would like to be able to actually see how the features will be used.
If you are going to implement the same interface in ixgbe as in niu (modulo bugs), then I have no objection to going ahead with this and then adding the option for driver-assigned locations later.
Quoted 6 lines
Please can you confirm that the location specified for
ETHTOOL_SRXCLSRLINSwill indeed be used as a priority in case of overlapping filters?Ben.
The ixgbe approach should be nearly identical in terms of how the priorities are based on the location of the filters. The original version from Santwona had the rule manager breaking the rules up into 7 sections so that rules that specified fewer fields would be near the end of the list. I'm pretty sure that was all due to priorities from what I could see in the niu driver since the filters that covered wider ranges were being made lower priority to be matched last.
In terms of overloading the get count call, that probably would be the best route in terms of changing rule manager behavior. The only thing I am having a hard time seeing is how the rule manager would be able to distinguish between low priority and high priority filter rules, or is this something that new keywords would be added to the parser for?
I just put out version 6 of the patches. Essentially I have reduced the size of the rule manager to being used only on insertion without any rule location specified. The one thing to keep in mind with this rule manager is that the rule at table size - 1 is always going to be the lowest priority rule. So if it was reserved for unspecified rules it would be easy to use something like that to achieve an "auto-select" location that the driver could then reassign as rules were added to it.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 1 line · Alexander Duyck
On 5/4/2011 11:45 AM, Ben Hutchings wrote:
[...]
Quoted 9 lines
Quoted 6 lines
Please can you confirm that the location specified for
ETHTOOL_SRXCLSRLINSwill indeed be used as a priority in case of overlapping filters?Ben.
The ixgbe approach should be nearly identical in terms of how the priorities are based on the location of the filters.
OK, good.
Quoted 6 lines
The original
version from Santwona had the rule manager breaking the rules up into 7 sections so that rules that specified fewer fields would be near the end of the list. I'm pretty sure that was all due to priorities from what I could see in the niu driver since the filters that covered wider ranges were being made lower priority to be matched last.
That would make sense.
Quoted 5 lines
In terms of overloading the get count call, that probably would be the best route in terms of changing rule manager behavior. The only thing I am having a hard time seeing is how the rule manager would be able to distinguish between low priority and high priority filter rules, or is this something that new keywords would be added to the parser for?
Right, there would have to be keywords to specify that.
Quoted 7 lines
I just put out version 6 of the patches. Essentially I have reduced the size of the rule manager to being used only on insertion without any rule location specified. The one thing to keep in mind with this rule manager is that the rule at table size - 1 is always going to be the lowest priority rule. So if it was reserved for unspecified rules it would be easy to use something like that to achieve an "auto-select" location that the driver could then reassign as rules were added to it.
I don't think any location value within the physical table size should select this special behaviour. The special location values for auto-select (with whatever priority) should be distinct from all the physical location values.
I still need to review your patches but it sounds like they will be ready to apply.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
In reply to Ben HutchingsQuoted 6 lines · Ben Hutchings
How about having
ETHTOOL_GRXCLSRLCNTset a flag in the 'data' field to indicate that the driver can assign locations? (We would have to specify that for compatibility with older kernels the application must initialise this filed to 0.)
rmgr_init()would then check for this flag.
I think this is a good suggestion if we want to support location selection by either the driver or ethtool. I also think ethtool's assumption that it is the only allocator and can allocate race-free is fundamentally flawed (take two parallel ethtools).
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
In reply to Alexander DuyckQuoted 37 lines · Alexander Duyck
Quoted 36 lines · Dimitris Michailidis
Quoted 34 lines · Ben Hutchings
Quoted 21 lines · Dimitris Michailidis
Quoted 10 lines · Ben Hutchings
Quoted 7 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is enough knowledge to pick an appropriate slot. So I'd remove theif (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location back for ethtool to report.
But first we have to specify this in the ethtool API. So please propose a patch to
ethtool.h.In the past we discussed that being able to specify the first available slot or the last available would be useful, so something like the below?
include/linux/ethtool.h +0
-0@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or Quoted 7 lines
%RX_CLS_FLOW_DISC
* if packets should be discarded
- * @location: Index of filter in hardware table
+ * @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for
+ * first available index, or %RX_CLS_FLOW_LAST_LOC for last
available[...]
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Quoted 5 lines
Quoted 3 lines
Easy and true for a TCAM. For hashing would you use the location to decide how to order filters that fall in the same bucket?
The problem is none of this is backwards compatible. The niu driver has supported the network flow classifier rules since 2.6.30. Adding this would cause all rule setups for niu to fail because these locations would have to exist outside of the current rule locations.
Looking at niu it already has a problem with its handling of location because it does
u16 idx; idx = nfc->fs.location;
i.e., it disregards the upper 16 bits of location. With the current code niu would return -EINVAL for the two new constants, which seems correct.
Quoted 2 lines
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location. We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
The problem with this is the location is dependent on the type of filter being added. I.e., the ioctl would need to get all the information the existing ioctl carries making the new ioctl a small superset of the current one. Additionally, if the driver only allocates a location in a separate ioctl how does it know that the app is actually going to use it?
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 55 lines · Dimitris Michailidis
Quoted 46 lines · Alexander Duyck
Quoted 36 lines · Dimitris Michailidis
Quoted 35 lines · Ben Hutchings
Quoted 32 lines · Dimitris Michailidis
Quoted 5 lines · Ben Hutchings
Quoted 4 lines · Dimitris Michailidis
I think
RX_CLS_LOC_UNSPECshould be passed to the driver, where there is
enough knowledge to pick an appropriate slot. So I'd remove theQuoted 8 lines
Quoted 5 lines
if (loc == RX_CLS_LOC_UNSPEC)block above, let the driver pick a slot, and then pass the selected location
back for ethtool to report.But first we have to specify this in the ethtool API. So please propose
a patch toethtool.h.In the past we discussed that being able to specify the first available slot or
the last available would be useful, so something like the below?include/linux/ethtool.h +0
-0@@ -442,7 +442,8 @@ struct ethtool_flow_ext {* includes the %FLOW_EXT flag. * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC
* if packets should be discarded
- * @location: Index of filter in hardware table
+ * @location: Index of filter in hardware table, or %RX_CLS_FLOW_FIRST_LOC for
+ * first available index, or %RX_CLS_FLOW_LAST_LOC for last
available[...]
Quoted 8 lines
Quoted 3 lines
I think that's reasonable. We should also explicitly state that location determines priority, i.e. if a packet matches two filters then the one with the lower location wins.
Easy and true for a TCAM. For hashing would you use the location to decide how
to order filters that fall in the same bucket?Quoted 4 lines
The problem is none of this is backwards compatible. The niu driver has supported the network flow classifier rules since 2.6.30. Adding this would cause all rule setups for niu to fail because these locations would have to exist outside of the current rule locations.
Looking at niu it already has a problem with its handling of location because it does
Quoted 6 lines
u16 idx; idx = nfc->fs.location;i.e., it disregards the upper 16 bits of location. With the current code niu would return
-EINVALfor the two new constants, which seems correct.
Actually it looks like this is going to trigger multiple bugs. Specifically since the upper 16 bits are being discarded it is possible to specify a value such as 0x10001 hex and it will misread that as 0x0001. This is something that will probably need to be fixed in niu.
Quoted 7 lines
Quoted 6 lines
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location. We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
Quoted 5 lines
The problem with this is the location is dependent on the type of filter being added. I.e., the ioctl would need to get all the information the existing ioctl carries making the new ioctl a small superset of the current one. Additionally, if the driver only allocates a location in a separate ioctl how does it know that the app is actually going to use it?
It doesn't know that the application is actually going to use it. What should happen is that the location should be verified by the driver when it is used in the rule insertion call. After all it is fully possible for the user to specify a location out of range since the insert call does no validation in ethtool if the user specified the location. That responsibility now lies with the driver.
Thanks,
Alex
Re: [ethtool PATCH 4/4] v5 Add RX packet classification interface
Quoted 8 lines · Alexander Duyck
Quoted 7 lines · Dimitris Michailidis
Quoted 5 lines · Alexander Duyck
This is why I was suggesting that the best approach would be to update the kernel to add a separate ioctl for letting the driver setup the location. We can just attempt to make that call and when we get the EOPNOTSUPP errno we know the device driver doesn't support it and can then let the rule manager take over.
Quoted 7 lines
Quoted 5 lines
The problem with this is the location is dependent on the type of filter being added. I.e., the ioctl would need to get all the information the existing ioctl carries making the new ioctl a small superset of the current one. Additionally, if the driver only allocates a location in a separate ioctl how does it know that the app is actually going to use it?
It doesn't know that the application is actually going to use it. What should happen is that the location should be verified by the driver when it is used in the rule insertion call. After all it is fully possible for the user to specify a location out of range since the insert call does no validation in ethtool if the user specified the location. That responsibility now lies with the driver.
That's not the problem I was pointing out. Of course the driver will verify the location it is given. The problem is if you have a separate ioctl call that only reserves a location (and it needs to reserve otherwise several of these calls can get the same value), if you don't use it you leave the driver with orphan reservations. Imagine you hit ^C between the two ioctls in ethtool.