netdevsim: impement proper device model
Subsystems (6)
cover netdevsim: impement proper device model
From: Jiri Pirko <[email protected]>
Currently the model of netdevsim is a bit odd in multiple ways.
1) devlink instance is not in any way related with actual netdevsim netdevices. Instead, it is created per-namespace.
2) multi-port netdevsim device is done using "link" attribute.
3) netdevsim bus is there only to have something to bind the netdev to, it really does not act as a bus.
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
echo "10 4" > /sys/bus/netdevsim/new_device
Then devlink shows this:
$ devlink dev netdevsim/netdevsim10
$ devlink port netdevsim/netdevsim10/0: type eth netdev netdevsim10p1 flavour physical netdevsim/netdevsim10/1: type eth netdev netdevsim10p2 flavour physical netdevsim/netdevsim10/2: type eth netdev netdevsim10p3 flavour physical netdevsim/netdevsim10/3: type eth netdev netdevsim10p4 flavour physical
Debugfs topology is also adjusted a bit. The rest stays the same as before.
TODO:
- teach udev to rename netdevsim netdevices similarly to pci netdevices
- fix tools/testing/selftests/bpf/test_offload.py to work with new iface
Jiri Pirko (15):
netdevsim: move device registration on bus to be done earlier in init
netdevsim: create devlink instance per netdevsim instance
netdevsim: rename devlink.c to dev.c to contain per-dev(asic) items
netdevsim: put netdevsim bus code into separate file
netdevsim: move device registration and related code to bus.c
netdevsim: add stub netdevsim driver implementation
netdevsim: use ida for bus device ids
netdevsim: add bus attributes to add new and delete devices
netdevsim: rename dev_init/exit() functions and make them independent
on ns
netdevsim: merge sdev into dev
netdevsim: generate random switch id instead of using dev id
netdevsim: change debugfs tree topology
netdevsim: implement dev probe/remove skeleton with port
initialization
netdevsim: move netdev creation/destruction to dev probe
netdevsim: implement ndo_get_devlink_port
drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/bpf.c | 92 ++--- drivers/net/netdevsim/bus.c | 305 +++++++++++++++ drivers/net/netdevsim/dev.c | 385 +++++++++++++++++++ drivers/net/netdevsim/devlink.c | 295 --------------- drivers/net/netdevsim/fib.c | 103 +++-- drivers/net/netdevsim/ipsec.c | 3 +- drivers/net/netdevsim/netdev.c | 396 +++++--------------- drivers/net/netdevsim/netdevsim.h | 124 +++--- tools/testing/selftests/bpf/test_offload.py | 12 +- tools/testing/selftests/net/rtnetlink.sh | 8 +- 11 files changed, 964 insertions(+), 761 deletions(-) create mode 100644 drivers/net/netdevsim/bus.c create mode 100644 drivers/net/netdevsim/dev.c delete mode 100644 drivers/net/netdevsim/devlink.c
Signature · 1 line
2.17.2
RFC PATCH 1/15 netdevsim: move device registration on bus to be done earlier in init
From: Jiri Pirko <[email protected]>
As a dependency of the subsequent patch, mode device registration to be done earlier, directly in nsim_newlink().
--- drivers/net/netdevsim/netdev.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/net/netdevsim/netdev.c +13 -13
@@ -174,25 +174,14 @@ static int nsim_init(struct net_device *dev)if (err) goto err_debugfs_destroy; - ns->dev.id = nsim_dev_id++; - ns->dev.bus = &nsim_bus; - ns->dev.type = &nsim_dev_type; - err =device_register (&ns->dev); -if (err) - goto err_bpf_uninit; - -SET_NETDEV_DEV (dev, &ns->dev); - err =nsim_devlink_setup (ns);if (err) - goto err_unreg_dev; + goto err_bpf_uninit;nsim_ipsec_init (ns);return 0 ; -err_unreg_dev: -device_unregister (&ns->dev); err_bpf_uninit:nsim_bpf_uninit (ns); err_debugfs_destroy:
@@ -514,11 +503,22 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,if (IS_ERR (ns->sdev))return PTR_ERR (ns->sdev); - err =register_netdevice (dev); + ns->dev.id = nsim_dev_id++; + ns->dev.bus = &nsim_bus; + ns->dev.type = &nsim_dev_type; + err =device_register (&ns->dev);if (err) goto err_sdev_put; + +SET_NETDEV_DEV (dev, &ns->dev); + + err =register_netdevice (dev); +if (err) + goto err_unreg_dev;return 0 ; +err_unreg_dev: +device_unregister (&ns->dev); err_sdev_put:nsim_sdev_put (ns->sdev);return err;
Signature · 1 line
2.17.2
RFC PATCH 2/15 netdevsim: create devlink instance per netdevsim instance
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Currently there is one devlink instance created per network namespace. That is quite odd considering the fact that devlink instance should represent an ASIC. The following patches are going to move the devlink instance even more down to a bus device, but until then, have one devlink instance per netdevsim instance. Struct nsim_devlink is introduced to hold fib setting.
--- drivers/net/netdevsim/devlink.c | 179 +++++++++++------------------- drivers/net/netdevsim/fib.c | 103 +++++++---------- drivers/net/netdevsim/netdev.c | 27 ++--- drivers/net/netdevsim/netdevsim.h | 18 +-- 4 files changed, 125 insertions(+), 202 deletions(-)
drivers/net/netdevsim/devlink.c +64 -115
@@ -15,59 +15,59 @@*/ #include <linux/device.h> +#include <linux/rtnetlink.h> #include <net/devlink.h> -#include <net/netns/generic.h> #include "netdevsim.h" -static unsigned int nsim_devlink_id; - -/* place holder until devlink and namespaces is sorted out */ -static struct net *nsim_devlink_net (struct devlink *devlink) -{ -return &init_net; -} +struct nsim_devlink { +struct nsim_fib_data *fib_data; +};/* IPv4 */ static u64 nsim_ipv4_fib_resource_occ_get (void *priv) { -struct net *net = priv; +struct nsim_devlink *nsim_devlink = priv; -return nsim_fib_get_val (net,NSIM_RESOURCE_IPV4_FIB , false); +return nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV4_FIB , false); }static u64 nsim_ipv4_fib_rules_res_occ_get (void *priv) { -struct net *net = priv; +struct nsim_devlink *nsim_devlink = priv; -return nsim_fib_get_val (net,NSIM_RESOURCE_IPV4_FIB_RULES , false); +return nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV4_FIB_RULES , false); }/* IPv6 */ static u64 nsim_ipv6_fib_resource_occ_get (void *priv) { -struct net *net = priv; +struct nsim_devlink *nsim_devlink = priv; -return nsim_fib_get_val (net,NSIM_RESOURCE_IPV6_FIB , false); +return nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV6_FIB , false); }static u64 nsim_ipv6_fib_rules_res_occ_get (void *priv) { -struct net *net = priv; +struct nsim_devlink *nsim_devlink = priv; -return nsim_fib_get_val (net,NSIM_RESOURCE_IPV6_FIB_RULES , false); +return nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV6_FIB_RULES , false); }static int devlink_resources_register (struct devlink *devlink) { +struct nsim_devlink *nsim_devlink =devlink_priv (devlink);struct devlink_resource_size_params params = { .size_max = (u64)-1 , .size_granularity =1 , .unit =DEVLINK_RESOURCE_UNIT_ENTRY }; -struct net *net =nsim_devlink_net (devlink);int err;u64 n;
@@ -81,7 +81,8 @@ static int devlink_resources_register(struct devlink *devlink) goto out; } - n =nsim_fib_get_val (net,NSIM_RESOURCE_IPV4_FIB , true); + n =nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV4_FIB , true); err =devlink_resource_register (devlink,"fib" , n,NSIM_RESOURCE_IPV4_FIB ,NSIM_RESOURCE_IPV4 , ¶ms);
@@ -90,7 +91,8 @@ static int devlink_resources_register(struct devlink *devlink)return err; } - n =nsim_fib_get_val (net,NSIM_RESOURCE_IPV4_FIB_RULES , true); + n =nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV4_FIB_RULES , true); err =devlink_resource_register (devlink,"fib-rules" , n,NSIM_RESOURCE_IPV4_FIB_RULES ,NSIM_RESOURCE_IPV4 , ¶ms);
@@ -109,7 +111,8 @@ static int devlink_resources_register(struct devlink *devlink) goto out; } - n =nsim_fib_get_val (net,NSIM_RESOURCE_IPV6_FIB , true); + n =nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV6_FIB , true); err =devlink_resource_register (devlink,"fib" , n,NSIM_RESOURCE_IPV6_FIB ,NSIM_RESOURCE_IPV6 , ¶ms);
@@ -118,7 +121,8 @@ static int devlink_resources_register(struct devlink *devlink)return err; } - n =nsim_fib_get_val (net,NSIM_RESOURCE_IPV6_FIB_RULES , true); + n =nsim_fib_get_val (nsim_devlink->fib_data, +NSIM_RESOURCE_IPV6_FIB_RULES , true); err =devlink_resource_register (devlink,"fib-rules" , n,NSIM_RESOURCE_IPV6_FIB_RULES ,NSIM_RESOURCE_IPV6 , ¶ms);
@@ -130,19 +134,19 @@ static int devlink_resources_register(struct devlink *devlink)devlink_resource_occ_get_register (devlink,NSIM_RESOURCE_IPV4_FIB , nsim_ipv4_fib_resource_occ_get, - net); + nsim_devlink);devlink_resource_occ_get_register (devlink,NSIM_RESOURCE_IPV4_FIB_RULES , nsim_ipv4_fib_rules_res_occ_get, - net); + nsim_devlink);devlink_resource_occ_get_register (devlink,NSIM_RESOURCE_IPV6_FIB , nsim_ipv6_fib_resource_occ_get, - net); + nsim_devlink);devlink_resource_occ_get_register (devlink,NSIM_RESOURCE_IPV6_FIB_RULES , nsim_ipv6_fib_rules_res_occ_get, - net); + nsim_devlink); out:return err; }
@@ -150,11 +154,11 @@ static int devlink_resources_register(struct devlink *devlink)static int nsim_devlink_reload (struct devlink *devlink,struct netlink_ext_ack *extack) { +struct nsim_devlink *nsim_devlink =devlink_priv (devlink);enum nsim_resource_id res_ids[] = {NSIM_RESOURCE_IPV4_FIB ,NSIM_RESOURCE_IPV4_FIB_RULES ,NSIM_RESOURCE_IPV6_FIB ,NSIM_RESOURCE_IPV6_FIB_RULES }; -struct net *net =nsim_devlink_net (devlink);int i;for (i =0 ; i <ARRAY_SIZE (res_ids); ++i) {
@@ -163,7 +167,8 @@ static int nsim_devlink_reload(struct devlink *devlink, err =devlink_resource_size_get (devlink, res_ids[i], &val);if (!err) { - err =nsim_fib_set_max (net, res_ids[i], val, extack); + err =nsim_fib_set_max (nsim_devlink->fib_data, + res_ids[i], val, extack);if (err)return err; }
@@ -172,124 +177,68 @@ static int nsim_devlink_reload(struct devlink *devlink,return 0 ; } -static void nsim_devlink_net_reset (struct net *net) -{ -enum nsim_resource_id res_ids[] = { -NSIM_RESOURCE_IPV4_FIB ,NSIM_RESOURCE_IPV4_FIB_RULES , -NSIM_RESOURCE_IPV6_FIB ,NSIM_RESOURCE_IPV6_FIB_RULES - }; -int i; - -for (i =0 ; i <ARRAY_SIZE (res_ids); ++i) { -if (nsim_fib_set_max (net, res_ids[i], (u64)-1 ,NULL )) { -pr_err ("Failed to reset limit for resource %u\n" , - res_ids[i]); - } - } -} -static const struct devlink_ops nsim_devlink_ops = { .reload = nsim_devlink_reload, }; -/* once devlink / namespace issues are sorted out -* this needs to be net in which a devlink instance -* is to be created. e.g., dev_net(ns->netdev) -*/ -static struct net *nsim_to_net (struct netdevsim *ns) +static int __nsim_devlink_init (struct netdevsim *ns) { -return &init_net; -} - -void nsim_devlink_teardown (struct netdevsim *ns) -{ -if (ns->devlink) { -struct net *net =nsim_to_net (ns); -bool *reg_devlink =net_generic (net, nsim_devlink_id); - -devlink_resources_unregister (ns->devlink,NULL ); -devlink_unregister (ns->devlink); -devlink_free (ns->devlink); - ns->devlink =NULL ; - -nsim_devlink_net_reset (net); - *reg_devlink = true; - } -} - -int nsim_devlink_setup (struct netdevsim *ns) -{ -struct net *net =nsim_to_net (ns); -bool *reg_devlink =net_generic (net, nsim_devlink_id); +struct nsim_devlink *nsim_devlink;struct devlink *devlink;int err; -/* only one device per namespace controls devlink */ -if (!*reg_devlink) { - ns->devlink =NULL ; -return 0 ; - } - - devlink =devlink_alloc (&nsim_devlink_ops,0 ); + devlink =devlink_alloc (&nsim_devlink_ops,sizeof (*nsim_devlink));if (!devlink)return -ENOMEM ; + nsim_devlink =devlink_priv (devlink); - err =devlink_register (devlink, &ns->dev); -if (err) + nsim_devlink->fib_data =nsim_fib_create (); +if (IS_ERR (nsim_devlink->fib_data)) { + err =PTR_ERR (nsim_devlink->fib_data); goto err_devlink_free; + } err =devlink_resources_register (devlink);if (err) - goto err_dl_unregister; + goto err_fib_destroy; - ns->devlink = devlink; + err =devlink_register (devlink, &ns->dev); +if (err) + goto err_resources_unregister; - *reg_devlink = false; + ns->devlink = devlink;return 0 ; -err_dl_unregister: -devlink_unregister (devlink); +err_resources_unregister: +devlink_resources_unregister (devlink,NULL ); +err_fib_destroy: +nsim_fib_destroy (nsim_devlink->fib_data); err_devlink_free:devlink_free (devlink);return err; } -/* Initialize per network namespace state */ -static int __net_init nsim_devlink_netns_init (struct net *net) +int nsim_devlink_init (struct netdevsim *ns) { -bool *reg_devlink =net_generic (net, nsim_devlink_id); - - *reg_devlink = true; - -return 0 ; -} - -static struct pernet_operations nsim_devlink_net_ops = { - .init = nsim_devlink_netns_init, - .id = &nsim_devlink_id, - .size =sizeof (bool ), -}; +int err; -void nsim_devlink_exit (void ) -{ -unregister_pernet_subsys (&nsim_devlink_net_ops); -nsim_fib_exit (); +dev_hold (ns->netdev); +rtnl_unlock (); + err =__nsim_devlink_init (ns); +rtnl_lock (); +dev_put (ns->netdev); +return err; } -int nsim_devlink_init (void ) +void nsim_devlink_exit (struct netdevsim *ns) { -int err; +struct devlink *devlink = ns->devlink; +struct nsim_devlink *nsim_devlink =devlink_priv (devlink); - err =nsim_fib_init (); -if (err) - goto err_out; - - err =register_pernet_subsys (&nsim_devlink_net_ops); -if (err) -nsim_fib_exit (); - -err_out: -return err; +devlink_unregister (devlink); +devlink_resources_unregister (devlink,NULL ); +nsim_fib_destroy (nsim_devlink->fib_data); +devlink_free (devlink); }
drivers/net/netdevsim/fib.c +42 -61
177 lines not on this page · raw message
drivers/net/netdevsim/netdev.c +10 -17
@@ -161,7 +161,6 @@ static int nsim_init(struct net_device *dev)char sdev_link_name[32 ];int err; - ns->netdev = dev; ns->ddir =debugfs_create_dir (netdev_name (dev), nsim_ddir);if (IS_ERR_OR_NULL (ns->ddir))return -ENOMEM ;
@@ -174,16 +173,10 @@ static int nsim_init(struct net_device *dev)if (err) goto err_debugfs_destroy; - err =nsim_devlink_setup (ns); -if (err) - goto err_bpf_uninit; -nsim_ipsec_init (ns);return 0 ; -err_bpf_uninit: -nsim_bpf_uninit (ns); err_debugfs_destroy:debugfs_remove_recursive (ns->ddir);return err;
@@ -194,7 +187,6 @@ static void nsim_uninit(struct net_device *dev)struct netdevsim *ns =netdev_priv (dev);nsim_ipsec_teardown (ns); -nsim_devlink_teardown (ns);debugfs_remove_recursive (ns->ddir);nsim_bpf_uninit (ns); }
@@ -203,6 +195,7 @@ static void nsim_free(struct net_device *dev) {struct netdevsim *ns =netdev_priv (dev); +nsim_devlink_exit (ns);device_unregister (&ns->dev);/* netdev and vf state will be freed out of device_release() */ nsim_sdev_put (ns->sdev);
@@ -511,12 +504,19 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev, goto err_sdev_put;SET_NETDEV_DEV (dev, &ns->dev); + ns->netdev = dev; - err =register_netdevice (dev); + err =nsim_devlink_init (ns);if (err) goto err_unreg_dev; + + err =register_netdevice (dev); +if (err) + goto err_devlink_exit;return 0 ; +err_devlink_exit: +nsim_devlink_exit (ns); err_unreg_dev:device_unregister (&ns->dev); err_sdev_put:
@@ -548,18 +548,12 @@ static int __init nsim_module_init(void)if (err) goto err_sdev_exit; - err =nsim_devlink_init (); -if (err) - goto err_unreg_bus; - err =rtnl_link_register (&nsim_link_ops);if (err) - goto err_dl_fini; + goto err_unreg_bus;return 0 ; -err_dl_fini: -nsim_devlink_exit (); err_unreg_bus:bus_unregister (&nsim_bus); err_sdev_exit:
@@ -572,7 +566,6 @@ static int __init nsim_module_init(void) static void __exit nsim_module_exit(void) {rtnl_link_unregister (&nsim_link_ops); -nsim_devlink_exit ();bus_unregister (&nsim_bus);nsim_sdev_exit ();debugfs_remove_recursive (nsim_ddir);
drivers/net/netdevsim/netdevsim.h +9 -9
@@ -30,6 +30,7 @@ struct bpf_prog;struct bpf_offload_dev ;struct dentry ;struct nsim_vf_config ; +struct nsim_fib_data ;struct netdevsim_shared_dev {unsigned int refcnt;
@@ -153,16 +154,15 @@ enum nsim_resource_id { NSIM_RESOURCE_IPV6_FIB_RULES, }; -int nsim_devlink_setup (struct netdevsim *ns); -void nsim_devlink_teardown (struct netdevsim *ns); +int nsim_devlink_init (struct netdevsim *ns); +void nsim_devlink_exit (struct netdevsim *ns); -int nsim_devlink_init (void ); -void nsim_devlink_exit (void ); - -int nsim_fib_init (void ); -void nsim_fib_exit (void ); -u64 nsim_fib_get_val (struct net *net,enum nsim_resource_id res_id,bool max); -int nsim_fib_set_max (struct net *net,enum nsim_resource_id res_id,u64 val, +struct nsim_fib_data *nsim_fib_create (void ); +void nsim_fib_destroy (struct nsim_fib_data *fib_data); +u64 nsim_fib_get_val (struct nsim_fib_data *fib_data, +enum nsim_resource_id res_id,bool max); +int nsim_fib_set_max (struct nsim_fib_data *fib_data, +enum nsim_resource_id res_id,u64 val,struct netlink_ext_ack *extack);#if IS_ENABLED (CONFIG_XFRM_OFFLOAD )
Signature · 1 line
2.17.2
Re: [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently there is one devlink instance created per network namespace. That is quite odd considering the fact that devlink instance should represent an ASIC. The following patches are going to move the devlink instance even more down to a bus device, but until then, have one devlink instance per netdevsim instance. Struct
nsim_devlinkis introduced to hold fib setting.
Quoted 7 lines
Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/netdevsim/devlink.c | 179 +++++++++++------------------- drivers/net/netdevsim/fib.c | 103 +++++++---------- drivers/net/netdevsim/netdev.c | 27 ++--- drivers/net/netdevsim/netdevsim.h | 18 +-- 4 files changed, 125 insertions(+), 202 deletions(-)
you are making a lot of changes to how fib events are handled and not explaining what you are doing.
Re: [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance
Quoted 18 lines · Mon, Apr 15, 2019 at 04:24:24AM CEST, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently there is one devlink instance created per network namespace. That is quite odd considering the fact that devlink instance should represent an ASIC. The following patches are going to move the devlink instance even more down to a bus device, but until then, have one devlink instance per netdevsim instance. Struct
nsim_devlinkis introduced to hold fib setting.Quoted 7 lines
Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/netdevsim/devlink.c | 179 +++++++++++------------------- drivers/net/netdevsim/fib.c | 103 +++++++---------- drivers/net/netdevsim/netdev.c | 27 ++--- drivers/net/netdevsim/netdevsim.h | 18 +-- 4 files changed, 125 insertions(+), 202 deletions(-)
Quoted 2 lines
you are making a lot of changes to how fib events are handled and not explaining what you are doing.
They are handled in the exact same way. This is just about devlink instance. Will add that to description.
Re: [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance
Quoted 19 lines · Jiri Pirko
Quoted 18 lines · Mon, Apr 15, 2019 at 04:24:24AM CEST, [email protected] wrote:
Quoted 16 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently there is one devlink instance created per network namespace. That is quite odd considering the fact that devlink instance should represent an ASIC. The following patches are going to move the devlink instance even more down to a bus device, but until then, have one devlink instance per netdevsim instance. Struct
nsim_devlinkis introduced to hold fib setting.Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/netdevsim/devlink.c | 179 +++++++++++------------------- drivers/net/netdevsim/fib.c | 103 +++++++---------- drivers/net/netdevsim/netdev.c | 27 ++--- drivers/net/netdevsim/netdevsim.h | 18 +-- 4 files changed, 125 insertions(+), 202 deletions(-)
Quoted 6 lines
Quoted 2 lines
you are making a lot of changes to how fib events are handled and not explaining what you are doing.
They are handled in the exact same way. This is just about devlink instance. Will add that to description.
Data is currently stored as a net_generic. You are changing that. The changelog should state that.
Re: [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance
Quoted 23 lines · Mon, Apr 15, 2019 at 05:07:04PM CEST, [email protected] wrote:
Quoted 22 lines · Jiri Pirko
Quoted 20 lines · Mon, Apr 15, 2019 at 04:24:24AM CEST, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently there is one devlink instance created per network namespace. That is quite odd considering the fact that devlink instance should represent an ASIC. The following patches are going to move the devlink instance even more down to a bus device, but until then, have one devlink instance per netdevsim instance. Struct
nsim_devlinkis introduced to hold fib setting.Quoted 7 lines
Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/netdevsim/devlink.c | 179 +++++++++++------------------- drivers/net/netdevsim/fib.c | 103 +++++++---------- drivers/net/netdevsim/netdev.c | 27 ++--- drivers/net/netdevsim/netdevsim.h | 18 +-- 4 files changed, 125 insertions(+), 202 deletions(-)you are making a lot of changes to how fib events are handled and not explaining what you are doing.
Quoted 7 lines
Quoted 3 lines
They are handled in the exact same way. This is just about devlink instance. Will add that to description.
Data is currently stored as a
net_generic. You are changing that. The changelog should state that.
Added that into description. Thanks.
RFC PATCH 3/15 netdevsim: rename devlink.c to dev.c to contain per-dev(asic) items
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
The existing devlink.c code is going to be extended to represent asic device on a bus. As this is about more than just devlink, rename the file. Do appropriate prefix renaming alongside with that.
---
drivers/net/netdevsim/Makefile | 2 +-
drivers/net/netdevsim/{devlink.c => dev.c} | 99 +++++++++++-----------
drivers/net/netdevsim/netdev.c | 10 +--
drivers/net/netdevsim/netdevsim.h | 4 +-
4 files changed, 56 insertions(+), 59 deletions(-)
rename drivers/net/netdevsim/{devlink.c => dev.c} (66%)drivers/net/netdevsim/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o devlink.o fib.o sdev.o \ + netdev.o dev.o fib.o sdev.o \ ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \
drivers/net/netdevsim/dev.c renamed from drivers/net/netdevsim/devlink.c +48 -51
226 lines not on this page · raw message
drivers/net/netdevsim/netdev.c +5 -5
@@ -195,7 +195,7 @@ static void nsim_free(struct net_device *dev) {struct netdevsim *ns =netdev_priv (dev); -nsim_devlink_exit (ns); +nsim_dev_exit (ns);device_unregister (&ns->dev);/* netdev and vf state will be freed out of device_release() */ nsim_sdev_put (ns->sdev);
@@ -506,17 +506,17 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,SET_NETDEV_DEV (dev, &ns->dev); ns->netdev = dev; - err =nsim_devlink_init (ns); + err =nsim_dev_init (ns);if (err) goto err_unreg_dev; err =register_netdevice (dev);if (err) - goto err_devlink_exit; + goto err_dev_exit;return 0 ; -err_devlink_exit: -nsim_devlink_exit (ns); +err_dev_exit: +nsim_dev_exit (ns); err_unreg_dev:device_unregister (&ns->dev); err_sdev_put:
drivers/net/netdevsim/netdevsim.h +2 -2
@@ -154,8 +154,8 @@ enum nsim_resource_id { NSIM_RESOURCE_IPV6_FIB_RULES, }; -int nsim_devlink_init (struct netdevsim *ns); -void nsim_devlink_exit (struct netdevsim *ns); +int nsim_dev_init (struct netdevsim *ns); +void nsim_dev_exit (struct netdevsim *ns);struct nsim_fib_data *nsim_fib_create (void );void nsim_fib_destroy (struct nsim_fib_data *fib_data);
Signature · 1 line
2.17.2
RFC PATCH 4/15 netdevsim: put netdevsim bus code into separate file
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the code related to netdevsim bus is going to get bigger, move the existing code to a separate file.
--- drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/bus.c | 24 ++++++++++++++++++++++++ drivers/net/netdevsim/netdev.c | 18 ++++++------------ drivers/net/netdevsim/netdevsim.h | 7 +++++++ 4 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 drivers/net/netdevsim/bus.c
drivers/net/netdevsim/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o fib.o sdev.o \ + netdev.o dev.o fib.o sdev.o bus.o \ ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \
drivers/net/netdevsim/bus.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2017 Netronome Systems, Inc. +* Copyright (C) 2019 Mellanox Technologies. All rights reserved +*/ + +#include <linux/device.h> + +#include "netdevsim.h" + +struct bus_type nsim_bus = { + .name =DRV_NAME , + .dev_name =DRV_NAME , + .num_vf = nsim_num_vf, +}; + +int nsim_bus_init (void ) +{ +return bus_register (&nsim_bus); +} + +void nsim_bus_exit (void ) +{ +bus_unregister (&nsim_bus); +}
drivers/net/netdevsim/netdev.c +6 -12
@@ -42,19 +42,13 @@ struct nsim_vf_config {static struct dentry *nsim_ddir; -static int nsim_num_vf (struct device *dev) +int nsim_num_vf (struct device *dev) {struct netdevsim *ns =to_nsim (dev);return ns->num_vfs; } -static struct bus_type nsim_bus = { - .name =DRV_NAME , - .dev_name =DRV_NAME , - .num_vf = nsim_num_vf, -}; -static int nsim_vfs_enable (struct netdevsim *ns,unsigned int num_vfs) { ns->vfconfigs = kcalloc(num_vfs, sizeof(struct nsim_vf_config),
@@ -544,18 +538,18 @@ static int __init nsim_module_init(void)if (err) goto err_debugfs_destroy; - err =bus_register (&nsim_bus); + err =nsim_bus_init ();if (err) goto err_sdev_exit; err =rtnl_link_register (&nsim_link_ops);if (err) - goto err_unreg_bus; + goto err_bus_exit;return 0 ; -err_unreg_bus: -bus_unregister (&nsim_bus); +err_bus_exit: +nsim_bus_exit (); err_sdev_exit:nsim_sdev_exit (); err_debugfs_destroy:
@@ -566,7 +560,7 @@ static int __init nsim_module_init(void) static void __exit nsim_module_exit(void) {rtnl_link_unregister (&nsim_link_ops); -bus_unregister (&nsim_bus); +nsim_bus_exit ();nsim_sdev_exit ();debugfs_remove_recursive (nsim_ddir); }
drivers/net/netdevsim/netdevsim.h +7 -0
@@ -188,3 +188,10 @@ static inline struct netdevsim *to_nsim(struct device *ptr) { return container_of(ptr, struct netdevsim, dev); } + +int nsim_num_vf (struct device *dev); + +extern struct bus_type nsim_bus; + +int nsim_bus_init (void ); +void nsim_bus_exit (void );
Signature · 1 line
2.17.2
David Miller
maintainerRe: [patch net-next rfc 04/15] netdevsim: put netdevsim bus code into separate file
From: Jiri Pirko <[email protected]>
Date: Sat, 13 Apr 2019 18:21:01 +0200
drivers/net/netdevsim/Makefile line 7
Quoted 7 lines
drivers/net/netdevsim/Makefile +1
-1@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o fib.o sdev.o \ + netdev.o dev.o fib.o sdev.o bus.o \
I know this is unrelated to what you are trying to do, but could you please also get rid of that trailing backslash?
Thank you.
Re: [patch net-next rfc 04/15] netdevsim: put netdevsim bus code into separate file
Quoted 6 lines · Sun, Apr 14, 2019 at 10:27:56PM CEST, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Sat, 13 Apr 2019 18:21:01 +0200Quoted 3 lines
drivers/net/netdevsim/Makefile +0
-0@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o
Quoted 7 lines
drivers/net/netdevsim/Makefile line 7
Quoted 4 lines
drivers/net/netdevsim/Makefile +1
-1netdevsim-objs := \ - netdev.o dev.o fib.o sdev.o \ + netdev.o dev.o fib.o sdev.o bus.o \I know this is unrelated to what you are trying to do, but could you please also get rid of that trailing backslash?
ok
Quoted 2 lines
Thank you.
RFC PATCH 5/15 netdevsim: move device registration and related code to bus.c
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Move netdevsim device registration into bus.c and alongside with that the related sysfs attributes. Introduce new struct nsim_bus_dev to represent a netdevsim device on netdevsim bus.
--- drivers/net/netdevsim/bus.c | 142 +++++++++++++++++++++- drivers/net/netdevsim/dev.c | 2 +- drivers/net/netdevsim/netdev.c | 195 +++++++----------------------- drivers/net/netdevsim/netdevsim.h | 31 +++-- 4 files changed, 207 insertions(+), 163 deletions(-)
drivers/net/netdevsim/bus.c +141 -1
@@ -4,15 +4,155 @@*/ #include <linux/device.h> +#include <linux/kernel.h> +#include <linux/rtnetlink.h> +#include <linux/slab.h> +#include <linux/sysfs.h> #include "netdevsim.h" -struct bus_type nsim_bus = { +static u32 nsim_bus_dev_id; + +static struct nsim_bus_dev *to_nsim_bus_dev (struct device *dev) +{ + return container_of(dev, struct nsim_bus_dev, dev); +} + +static int nsim_bus_dev_vfs_enable (struct nsim_bus_dev *nsim_bus_dev, +unsigned int num_vfs) +{ + nsim_bus_dev->vfconfigs =kcalloc (num_vfs, +sizeof (struct nsim_vf_config ), +GFP_KERNEL ); +if (!nsim_bus_dev->vfconfigs) +return -ENOMEM ; + nsim_bus_dev->num_vfs = num_vfs; + +return 0 ; +} + +static void nsim_bus_dev_vfs_disable (struct nsim_bus_dev *nsim_bus_dev) +{ +kfree (nsim_bus_dev->vfconfigs); + nsim_bus_dev->vfconfigs =NULL ; + nsim_bus_dev->num_vfs =0 ; +} + +static ssize_t +nsim_bus_dev_numvfs_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); +unsigned int num_vfs; +int ret; + + ret =kstrtouint (buf,0 , &num_vfs); +if (ret) +return ret; + +rtnl_lock (); +if (nsim_bus_dev->num_vfs == num_vfs) + goto exit_good; +if (nsim_bus_dev->num_vfs && num_vfs) { + ret = -EBUSY ; + goto exit_unlock; + } + +if (num_vfs) { + ret =nsim_bus_dev_vfs_enable (nsim_bus_dev, num_vfs); +if (ret) + goto exit_unlock; + }else { +nsim_bus_dev_vfs_disable (nsim_bus_dev); + } +exit_good: + ret = count; +exit_unlock: +rtnl_unlock (); + +return ret; +} + +static ssize_t +nsim_bus_dev_numvfs_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); + +return sprintf (buf,"%u\n" , nsim_bus_dev->num_vfs); +} + +static struct device_attribute nsim_bus_dev_numvfs_attr = +__ATTR (sriov_numvfs,0664 , nsim_bus_dev_numvfs_show, + nsim_bus_dev_numvfs_store); + +static struct attribute *nsim_bus_dev_attrs[] = { + &nsim_bus_dev_numvfs_attr.attr, +NULL , +}; + +static const struct attribute_group nsim_bus_dev_attr_group = { + .attrs = nsim_bus_dev_attrs, +}; + +static const struct attribute_group *nsim_bus_dev_attr_groups[] = { + &nsim_bus_dev_attr_group, +NULL , +}; + +static void nsim_bus_dev_release (struct device *dev) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); + +nsim_bus_dev_vfs_disable (nsim_bus_dev); +} + +static struct device_type nsim_bus_dev_type = { + .groups = nsim_bus_dev_attr_groups, + .release = nsim_bus_dev_release, +}; + +int nsim_num_vf (struct device *dev) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); + +return nsim_bus_dev->num_vfs; +} + +static struct bus_type nsim_bus = { .name =DRV_NAME , .dev_name =DRV_NAME , .num_vf = nsim_num_vf, }; +struct nsim_bus_dev *nsim_bus_dev_new (void ) +{ +struct nsim_bus_dev *nsim_bus_dev; +int err; + + nsim_bus_dev =kzalloc (sizeof (*nsim_bus_dev),GFP_KERNEL ); +if (!nsim_bus_dev) +return ERR_PTR (-ENOMEM ); + + nsim_bus_dev->dev.id = nsim_bus_dev_id++; + nsim_bus_dev->dev.bus = &nsim_bus; + nsim_bus_dev->dev.type = &nsim_bus_dev_type; + err =device_register (&nsim_bus_dev->dev); +if (err) + goto err_nsim_bus_dev_free; +return nsim_bus_dev; + +err_nsim_bus_dev_free: +kfree (nsim_bus_dev); +return ERR_PTR (err); +} + +void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev) +{ +device_unregister (&nsim_bus_dev->dev); +kfree (nsim_bus_dev); +} +int nsim_bus_init (void ) {return bus_register (&nsim_bus);
drivers/net/netdevsim/dev.c +1 -1
@@ -199,7 +199,7 @@ static int __nsim_dev_init(struct netdevsim *ns)if (err) goto err_fib_destroy; - err =devlink_register (devlink, &ns->dev); + err =devlink_register (devlink, &ns->nsim_bus_dev->dev);if (err) goto err_resources_unregister;
drivers/net/netdevsim/netdev.c +45 -150
301 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +20 -11
@@ -85,14 +85,11 @@ struct netdevsim {u64 tx_bytes;struct u64_stats_sync syncp; -struct device dev; +struct nsim_bus_dev *nsim_bus_dev;struct netdevsim_shared_dev *sdev;struct dentry *ddir; -unsigned int num_vfs; -struct nsim_vf_config *vfconfigs; -struct bpf_prog *bpf_offloaded;u32 bpf_offloaded_id;
@@ -184,14 +181,26 @@ static inline bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb) }#endif -static inline struct netdevsim *to_nsim (struct device *ptr) -{ - return container_of(ptr, struct netdevsim, dev); -} - -int nsim_num_vf (struct device *dev); +struct nsim_vf_config { +int link_state; +u16 min_tx_rate; +u16 max_tx_rate; +u16 vlan; +__be16 vlan_proto; +u16 qos; +u8 vf_mac[ETH_ALEN ]; +bool spoofchk_enabled; +bool trusted; +bool rss_query_enabled; +}; -extern struct bus_type nsim_bus; +struct nsim_bus_dev { +struct device dev; +unsigned int num_vfs; +struct nsim_vf_config *vfconfigs; +}; +struct nsim_bus_dev *nsim_bus_dev_new (void ); +void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev);int nsim_bus_init (void );void nsim_bus_exit (void );
Signature · 1 line
2.17.2
RFC PATCH 6/15 netdevsim: add stub netdevsim driver implementation
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In order to bus probing to work correctly, register a simple netdevsim driver implementation.
--- drivers/net/netdevsim/bus.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/net/netdevsim/bus.c +20 -1
@@ -153,12 +153,31 @@ void nsim_bus_dev_del(struct nsim_bus_dev *nsim_bus_dev)kfree (nsim_bus_dev); } +static struct device_driver nsim_driver = { + .name =DRV_NAME , + .bus = &nsim_bus, + .owner =THIS_MODULE , +}; +int nsim_bus_init (void ) { -return bus_register (&nsim_bus); +int err; + + err =bus_register (&nsim_bus); +if (err) +return err; + err =driver_register (&nsim_driver); +if (err) + goto err_bus_unregister; +return 0 ; + +err_bus_unregister: +bus_unregister (&nsim_bus); +return err; }void nsim_bus_exit (void ) { +driver_unregister (&nsim_driver);bus_unregister (&nsim_bus); }
Signature · 1 line
2.17.2
RFC PATCH 7/15 netdevsim: use ida for bus device ids
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Instead of increments of u32 value, use ida to manage bus device ids.
--- drivers/net/netdevsim/bus.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/net/netdevsim/bus.c +10 -3
@@ -4,6 +4,7 @@*/ #include <linux/device.h> +#include <linux/idr.h> #include <linux/kernel.h> #include <linux/rtnetlink.h> #include <linux/slab.h>
@@ -11,7 +12,7 @@#include "netdevsim.h" -static u32 nsim_bus_dev_id; +static DEFINE_IDA (nsim_bus_dev_ids);static struct nsim_bus_dev *to_nsim_bus_dev (struct device *dev) {
@@ -134,14 +135,19 @@ struct nsim_bus_dev *nsim_bus_dev_new(void)if (!nsim_bus_dev)return ERR_PTR (-ENOMEM ); - nsim_bus_dev->dev.id = nsim_bus_dev_id++; + err =ida_alloc (&nsim_bus_dev_ids,GFP_KERNEL ); +if (err <0 ) + goto err_nsim_bus_dev_free; + nsim_bus_dev->dev.id = err; nsim_bus_dev->dev.bus = &nsim_bus; nsim_bus_dev->dev.type = &nsim_bus_dev_type; err =device_register (&nsim_bus_dev->dev);if (err) - goto err_nsim_bus_dev_free; + goto err_nsim_bus_dev_id_free;return nsim_bus_dev; +err_nsim_bus_dev_id_free: +ida_free (&nsim_bus_dev_ids, nsim_bus_dev->dev.id); err_nsim_bus_dev_free:kfree (nsim_bus_dev);return ERR_PTR (err);
@@ -150,6 +156,7 @@ struct nsim_bus_dev *nsim_bus_dev_new(void)void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev) {device_unregister (&nsim_bus_dev->dev); +ida_free (&nsim_bus_dev_ids, nsim_bus_dev->dev.id);kfree (nsim_bus_dev); }
Signature · 1 line
2.17.2
RFC PATCH 8/15 netdevsim: add bus attributes to add new and delete devices
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add a way to add new netdevsim device on netdevsim bus and also to delete existing netdevsim device from the bus. Track the bus devices in using a list.
--- drivers/net/netdevsim/bus.c | 97 ++++++++++++++++++++++++++++++- drivers/net/netdevsim/netdev.c | 2 +- drivers/net/netdevsim/netdevsim.h | 4 +- 3 files changed, 99 insertions(+), 4 deletions(-)
drivers/net/netdevsim/bus.c +95 -2
@@ -6,6 +6,8 @@#include <linux/device.h> #include <linux/idr.h> #include <linux/kernel.h> +#include <linux/list.h> +#include <linux/mutex.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/sysfs.h>
@@ -13,6 +15,8 @@#include "netdevsim.h" static DEFINE_IDA (nsim_bus_dev_ids); +static LIST_HEAD (nsim_bus_dev_list); +static DEFINE_MUTEX (nsim_bus_dev_list_lock);static struct nsim_bus_dev *to_nsim_bus_dev (struct device *dev) {
@@ -113,6 +117,83 @@ static struct device_type nsim_bus_dev_type = { .release = nsim_bus_dev_release, }; +static ssize_t new_device_store (struct bus_type *bus,const char *buf, +size_t count) +{ +struct nsim_bus_dev *nsim_bus_dev; +unsigned int port_count; +unsigned int id; +int err; + + err =sscanf (buf,"%u %u" , &id, &port_count); +switch (err) { +case 1 : + port_count =1 ; +/* pass through */ +case 2 : +if (id >INT_MAX ) { +pr_err ("Value of \"id\" is too big.\n" ); +return -EINVAL ; + } +break ; +default : +pr_err ("Format for adding new device is \"id port_count\" (uint uint).\n" ); +return -EINVAL ; + } + nsim_bus_dev =nsim_bus_dev_new (id, port_count); +if (IS_ERR (nsim_bus_dev)) +return PTR_ERR (nsim_bus_dev); + +mutex_lock (&nsim_bus_dev_list_lock); +list_add_tail (&nsim_bus_dev->list, &nsim_bus_dev_list); +mutex_unlock (&nsim_bus_dev_list_lock); + +return count; +} +static BUS_ATTR_WO (new_device); + +static ssize_t del_device_store (struct bus_type *bus,const char *buf, +size_t count) +{ +struct nsim_bus_dev *nsim_bus_dev, *tmp; +unsigned int id; +int err; + + err =sscanf (buf,"%u" , &id); +switch (err) { +case 1 : +if (id >INT_MAX ) { +pr_err ("Value of \"id\" is too big.\n" ); +return -EINVAL ; + } +break ; +default : +pr_err ("Format for deleting device is \"id\" (uint).\n" ); +return -EINVAL ; + } + + err = -ENOENT ; +mutex_lock (&nsim_bus_dev_list_lock); +list_for_each_entry_safe (nsim_bus_dev, tmp, &nsim_bus_dev_list, list) { +if (nsim_bus_dev->dev.id != id) +continue ; +list_del (&nsim_bus_dev->list); +nsim_bus_dev_del (nsim_bus_dev); + err =0 ; +break ; + } +mutex_unlock (&nsim_bus_dev_list_lock); +return !err ? count : err; +} +static BUS_ATTR_WO (del_device); + +static struct attribute *nsim_bus_attrs[] = { + &bus_attr_new_device.attr, + &bus_attr_del_device.attr, +NULL +}; +ATTRIBUTE_GROUPS (nsim_bus); +int nsim_num_vf (struct device *dev) {struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev);
@@ -123,10 +204,11 @@ int nsim_num_vf(struct device *dev)static struct bus_type nsim_bus = { .name =DRV_NAME , .dev_name =DRV_NAME , + .bus_groups = nsim_bus_groups, .num_vf = nsim_num_vf, }; -struct nsim_bus_dev *nsim_bus_dev_new (void ) +struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id,unsigned int port_count) {struct nsim_bus_dev *nsim_bus_dev;int err;
@@ -135,12 +217,15 @@ struct nsim_bus_dev *nsim_bus_dev_new(void)if (!nsim_bus_dev)return ERR_PTR (-ENOMEM ); - err =ida_alloc (&nsim_bus_dev_ids,GFP_KERNEL ); + err =ida_alloc_range (&nsim_bus_dev_ids, + id == ~0 ?0 : id, id,GFP_KERNEL );if (err <0 ) goto err_nsim_bus_dev_free; nsim_bus_dev->dev.id = err; nsim_bus_dev->dev.bus = &nsim_bus; nsim_bus_dev->dev.type = &nsim_bus_dev_type; + nsim_bus_dev->port_count = port_count; + err =device_register (&nsim_bus_dev->dev);if (err) goto err_nsim_bus_dev_id_free;
@@ -185,6 +270,14 @@ int nsim_bus_init(void)void nsim_bus_exit (void ) { +struct nsim_bus_dev *nsim_bus_dev, *tmp; + +mutex_lock (&nsim_bus_dev_list_lock); +list_for_each_entry_safe (nsim_bus_dev, tmp, &nsim_bus_dev_list, list) { +list_del (&nsim_bus_dev->list); +nsim_bus_dev_del (nsim_bus_dev); + } +mutex_unlock (&nsim_bus_dev_list_lock);driver_unregister (&nsim_driver);bus_unregister (&nsim_bus); }
drivers/net/netdevsim/netdev.c +1 -1
@@ -386,7 +386,7 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,if (IS_ERR (ns->sdev))return PTR_ERR (ns->sdev); - ns->nsim_bus_dev =nsim_bus_dev_new (); + ns->nsim_bus_dev =nsim_bus_dev_new (~0 ,0 );if (IS_ERR (ns->nsim_bus_dev)) { err =PTR_ERR (ns->nsim_bus_dev); goto err_sdev_put;
drivers/net/netdevsim/netdevsim.h +3 -1
@@ -196,11 +196,13 @@ struct nsim_vf_config {struct nsim_bus_dev {struct device dev; +struct list_head list; +unsigned int port_count;unsigned int num_vfs;struct nsim_vf_config *vfconfigs; }; -struct nsim_bus_dev *nsim_bus_dev_new (void ); +struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id,unsigned int port_count);void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev);int nsim_bus_init (void );void nsim_bus_exit (void );
Signature · 1 line
2.17.2
RFC PATCH 9/15 netdevsim: rename dev_init/exit() functions and make them independent on ns
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
These functions are going to be called from bus probe/release(), therefore make them independent on ns struct and rename accordingly.
--- drivers/net/netdevsim/dev.c | 31 ++++++++++++------------------- drivers/net/netdevsim/netdev.c | 14 ++++++++------ drivers/net/netdevsim/netdevsim.h | 11 ++++++++--- 3 files changed, 28 insertions(+), 28 deletions(-)
drivers/net/netdevsim/dev.c +12 -19
@@ -21,10 +21,6 @@#include "netdevsim.h" -struct nsim_dev { -struct nsim_fib_data *fib_data; -}; -static u64 nsim_dev_ipv4_fib_resource_occ_get (void *priv) {struct nsim_dev *nsim_dev = priv;
@@ -178,7 +174,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .reload = nsim_dev_reload, }; -static int __nsim_dev_init (struct netdevsim *ns) +static struct nsim_dev *nsim_dev_create (struct nsim_bus_dev *nsim_bus_dev) {struct nsim_dev *nsim_dev;struct devlink *devlink;
@@ -186,7 +182,7 @@ static int __nsim_dev_init(struct netdevsim *ns) devlink =devlink_alloc (&nsim_dev_devlink_ops,sizeof (*nsim_dev));if (!devlink) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); nsim_dev =devlink_priv (devlink); nsim_dev->fib_data =nsim_fib_create ();
@@ -199,13 +195,11 @@ static int __nsim_dev_init(struct netdevsim *ns)if (err) goto err_fib_destroy; - err =devlink_register (devlink, &ns->nsim_bus_dev->dev); + err =devlink_register (devlink, &nsim_bus_dev->dev);if (err) goto err_resources_unregister; - ns->devlink = devlink; - -return 0 ; +return nsim_dev; err_resources_unregister:devlink_resources_unregister (devlink,NULL );
@@ -213,26 +207,25 @@ static int __nsim_dev_init(struct netdevsim *ns)nsim_fib_destroy (nsim_dev->fib_data); err_devlink_free:devlink_free (devlink); - -return err; +return ERR_PTR (err); } -int nsim_dev_init (struct netdevsim *ns) +struct nsim_dev *nsim_dev_create_with_ns (struct nsim_bus_dev *nsim_bus_dev, +struct netdevsim *ns) { -int err; +struct nsim_dev *nsim_dev;dev_hold (ns->netdev);rtnl_unlock (); - err =__nsim_dev_init (ns); + nsim_dev =nsim_dev_create (nsim_bus_dev);rtnl_lock ();dev_put (ns->netdev); -return err; +return nsim_dev; } -void nsim_dev_exit (struct netdevsim *ns) +void nsim_dev_destroy (struct nsim_dev *nsim_dev) { -struct devlink *devlink = ns->devlink; -struct nsim_dev *nsim_dev =devlink_priv (devlink); +struct devlink *devlink =priv_to_devlink (nsim_dev);devlink_unregister (devlink);devlink_resources_unregister (devlink,NULL );
drivers/net/netdevsim/netdev.c +8 -6
@@ -77,7 +77,7 @@ static void nsim_free(struct net_device *dev) {struct netdevsim *ns =netdev_priv (dev); -nsim_dev_exit (ns); +nsim_dev_destroy (ns->nsim_dev);nsim_bus_dev_del (ns->nsim_bus_dev);/* netdev and vf state will be freed out of device_release() */ nsim_sdev_put (ns->sdev);
@@ -395,17 +395,19 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,SET_NETDEV_DEV (dev, &ns->nsim_bus_dev->dev); ns->netdev = dev; - err =nsim_dev_init (ns); -if (err) + ns->nsim_dev =nsim_dev_create_with_ns (ns->nsim_bus_dev, ns); +if (IS_ERR (ns->nsim_dev)) { + err =PTR_ERR (ns->nsim_dev); goto err_dev_del; + } err =register_netdevice (dev);if (err) - goto err_dev_exit; + goto err_dev_destroy;return 0 ; -err_dev_exit: -nsim_dev_exit (ns); +err_dev_destroy: +nsim_dev_destroy (ns->nsim_dev); err_dev_del:nsim_bus_dev_del (ns->nsim_bus_dev); err_sdev_put:
drivers/net/netdevsim/netdevsim.h +8 -3
@@ -80,6 +80,7 @@ struct nsim_ipsec {struct netdevsim {struct net_device *netdev; +struct nsim_dev *nsim_dev;u64 tx_packets;u64 tx_bytes;
@@ -102,7 +103,6 @@ struct netdevsim {bool bpf_xdpoffload_accept;bool bpf_map_accept; -struct devlink *devlink;struct nsim_ipsec ipsec; };
@@ -151,8 +151,13 @@ enum nsim_resource_id { NSIM_RESOURCE_IPV6_FIB_RULES, }; -int nsim_dev_init (struct netdevsim *ns); -void nsim_dev_exit (struct netdevsim *ns); +struct nsim_dev { +struct nsim_fib_data *fib_data; +}; + +struct nsim_dev *nsim_dev_create_with_ns (struct nsim_bus_dev *nsim_bus_dev, +struct netdevsim *ns); +void nsim_dev_destroy (struct nsim_dev *nsim_dev);struct nsim_fib_data *nsim_fib_create (void );void nsim_fib_destroy (struct nsim_fib_data *fib_data);
Signature · 1 line
2.17.2
RFC PATCH 10/15 netdevsim: merge sdev into dev
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As previously introduce dev which is mapped 1:1 to a bus device covers the purpose of the original shared device, merge the sdev code into dev.
--- drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/bpf.c | 79 +++++++++------------ drivers/net/netdevsim/dev.c | 47 ++++++++++++ drivers/net/netdevsim/netdev.c | 49 ++++--------- drivers/net/netdevsim/netdevsim.h | 54 ++++++-------- tools/testing/selftests/bpf/test_offload.py | 8 +-- 6 files changed, 120 insertions(+), 119 deletions(-)
drivers/net/netdevsim/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o fib.o sdev.o bus.o \ + netdev.o dev.o fib.o bus.o \ ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \
drivers/net/netdevsim/bpf.c +33 -46
165 lines not on this page · raw message
drivers/net/netdevsim/dev.c +47 -0
81 lines not on this page · raw message
drivers/net/netdevsim/netdev.c +13 -36
111 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +22 -32
90 lines not on this page · raw message
tools/testing/selftests/bpf/test_offload.py +4 -4
@@ -335,7 +335,7 @@ class NetdevSim: self.ns = "" self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname']) - self.sdev_dir = self.dfs_dir + '/sdev/' + self.dev_dir = self.dfs_dir + '/dev/' self.dfs_refresh() def __getitem__(self, key):
@@ -368,12 +368,12 @@ class NetdevSim: return data.strip() def dfs_num_bound_progs(self): - path = os.path.join(self.sdev_dir, "bpf_bound_progs") + path = os.path.join(self.dev_dir, "bpf_bound_progs") _, progs = cmd('ls %s' % (path)) return len(progs.split()) def dfs_get_bound_progs(self, expected): - progs = DebugfsDir(os.path.join(self.sdev_dir, "bpf_bound_progs")) + progs = DebugfsDir(os.path.join(self.dev_dir, "bpf_bound_progs")) if expected is not None: if len(progs) != expected: fail(True, "%d BPF programs bound, expected %d" %
@@ -1055,7 +1055,7 @@ try: start_test("Test if netdev removal waits for translation...") delay_msec = 500 - sim.dfs["sdev/bpf_bind_verifier_delay"] = delay_msec + sim.dfs["dev/bpf_bind_verifier_delay"] = delay_msec start = time.time() cmd_line = "tc filter add dev %s ingress bpf %s da skip_sw" % \ (sim['ifname'], obj)
Signature · 1 line
2.17.2
Re: [patch net-next rfc 10/15] netdevsim: merge sdev into dev
Quoted 6 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As previously introduce dev which is mapped 1:1 to a bus device covers the purpose of the original shared device, merge the sdev code into dev.
Signed-off-by Jiri Pirko <[email protected]>
One ASIC may have multiple bus devices. sdev is ASIC.
Re: [patch net-next rfc 10/15] netdevsim: merge sdev into dev
Quoted 9 lines · Mon, Apr 15, 2019 at 10:49:46PM CEST, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As previously introduce dev which is mapped 1:1 to a bus device covers the purpose of the original shared device, merge the sdev code into dev.
Signed-off-by Jiri Pirko <[email protected]>One ASIC may have multiple bus devices. sdev is ASIC.
Yeah, that is a generic problem. That would be job for "devlink aliases".
RFC PATCH 11/15 netdevsim: generate random switch id instead of using dev id
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Current implementation of parent_id/switch_id does not follow the original idea of being unique. The values are "0", "1", etc. Instead of that, generate 32 random bytes.
--- drivers/net/netdevsim/dev.c | 3 +++ drivers/net/netdevsim/netdev.c | 3 +-- drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/netdevsim/dev.c +3 -0
@@ -17,6 +17,7 @@#include <linux/debugfs.h> #include <linux/device.h> +#include <linux/random.h> #include <linux/rtnetlink.h> #include <net/devlink.h>
@@ -204,6 +205,8 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)return ERR_PTR (-ENOMEM ); nsim_dev =devlink_priv (devlink); nsim_dev->nsim_bus_dev = nsim_bus_dev; + nsim_dev->switch_id.id_len =sizeof (nsim_dev->switch_id.id); +get_random_bytes (nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); nsim_dev->fib_data =nsim_fib_create ();if (IS_ERR (nsim_dev->fib_data)) {
drivers/net/netdevsim/netdev.c +1 -2
@@ -32,8 +32,7 @@ static int nsim_get_port_parent_id(struct net_device *dev, {struct netdevsim *ns =netdev_priv (dev); - ppid->id_len =sizeof (ns->nsim_dev->nsim_bus_dev->dev.id); -memcpy (&ppid->id, &ns->nsim_dev->nsim_bus_dev->dev.id, ppid->id_len); +memcpy (ppid, &ns->nsim_dev->switch_id,sizeof (*ppid));return 0 ; }
drivers/net/netdevsim/netdevsim.h +1 -0
@@ -141,6 +141,7 @@ struct nsim_dev {u32 prog_id_gen;struct list_head bpf_bound_progs;struct list_head bpf_bound_maps; +struct netdev_phys_item_id switch_id; }; struct nsim_dev *nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
Signature · 1 line
2.17.2
RFC PATCH 12/15 netdevsim: change debugfs tree topology
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
With the model where dev is represented by devlink and ports are represented by devlink ports, make debugfs file names independent on netdev names. Change the topology to the one illustrated by the following example:
$ ls /sys/kernel/debug/netdevsim/ netdevsim1 $ ls /sys/kernel/debug/netdevsim/netdevsim1/ bpf_bind_accept bpf_bind_verifier_delay bpf_bound_progs ports $ ls /sys/kernel/debug/netdevsim/netdevsim1/ports/ 0 1 $ ls /sys/kernel/debug/netdevsim/netdevsim1/ports/0/ bpf_map_accept bpf_offloaded_id bpf_tc_accept bpf_tc_non_bound_accept bpf_xdpdrv_accept bpf_xdpoffload_accept dev ipsec $ ls /sys/kernel/debug/netdevsim/netdevsim1/ports/0/dev -l lrwxrwxrwx 1 root root 0 Apr 13 15:58 /sys/kernel/debug/netdevsim/netdevsim1/ports/0/dev -> ../../../netdevsim1
--- drivers/net/netdevsim/dev.c | 10 +++++++--- drivers/net/netdevsim/netdev.c | 15 +++------------ drivers/net/netdevsim/netdevsim.h | 1 + tools/testing/selftests/bpf/test_offload.py | 4 +++- tools/testing/selftests/net/rtnetlink.sh | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-)
drivers/net/netdevsim/dev.c +7 -3
@@ -27,17 +27,21 @@ static struct dentry *nsim_dev_ddir;static int nsim_dev_debugfs_init (struct nsim_dev *nsim_dev) { -char dev_ddir_name[10 ]; +char dev_ddir_name[16 ]; -sprintf (dev_ddir_name,"%u" , nsim_dev->nsim_bus_dev->dev.id); +sprintf (dev_ddir_name,DRV_NAME "%u" , nsim_dev->nsim_bus_dev->dev.id); nsim_dev->ddir =debugfs_create_dir (dev_ddir_name, nsim_dev_ddir);if (IS_ERR_OR_NULL (nsim_dev->ddir))return PTR_ERR_OR_ZERO (nsim_dev->ddir) ?: -EINVAL ; + nsim_dev->ports_ddir =debugfs_create_dir ("ports" , nsim_dev->ddir); +if (IS_ERR_OR_NULL (nsim_dev->ports_ddir)) +return PTR_ERR_OR_ZERO (nsim_dev->ports_ddir) ?: -EINVAL ;return 0 ; }static void nsim_dev_debugfs_exit (struct nsim_dev *nsim_dev) { +debugfs_remove_recursive (nsim_dev->ports_ddir);debugfs_remove_recursive (nsim_dev->ddir); }
@@ -272,7 +276,7 @@ void nsim_dev_destroy(struct nsim_dev *nsim_dev)int nsim_dev_init (void ) { - nsim_dev_ddir =debugfs_create_dir (DRV_NAME "_dev" ,NULL ); + nsim_dev_ddir =debugfs_create_dir (DRV_NAME ,NULL );if (IS_ERR_OR_NULL (nsim_dev_ddir))return -ENOMEM ;return 0 ;
drivers/net/netdevsim/netdev.c +3 -12
@@ -25,8 +25,6 @@#include "netdevsim.h" -static struct dentry *nsim_ddir; -static int nsim_get_port_parent_id (struct net_device *dev,struct netdev_phys_item_id *ppid) {
@@ -42,11 +40,11 @@ static int nsim_init(struct net_device *dev)char dev_link_name[32 ];int err; - ns->ddir =debugfs_create_dir (netdev_name (dev), nsim_ddir); + ns->ddir =debugfs_create_dir ("0" , ns->nsim_dev->ports_ddir);if (IS_ERR_OR_NULL (ns->ddir))return -ENOMEM ; -sprintf (dev_link_name,"../../" DRV_NAME "_dev/%u" , +sprintf (dev_link_name,"../../../" DRV_NAME "%u" , ns->nsim_dev->nsim_bus_dev->dev.id);debugfs_create_symlink ("dev" , ns->ddir, dev_link_name);
@@ -403,13 +401,9 @@ static int __init nsim_module_init(void) {int err; - nsim_ddir =debugfs_create_dir (DRV_NAME ,NULL ); -if (IS_ERR_OR_NULL (nsim_ddir)) -return -ENOMEM ; - err =nsim_dev_init ();if (err) - goto err_debugfs_destroy; +return err; err =nsim_bus_init ();if (err)
@@ -425,8 +419,6 @@ static int __init nsim_module_init(void)nsim_bus_exit (); err_dev_exit:nsim_dev_exit (); -err_debugfs_destroy: -debugfs_remove_recursive (nsim_ddir);return err; }
@@ -435,7 +427,6 @@ static void __exit nsim_module_exit(void)rtnl_link_unregister (&nsim_link_ops);nsim_bus_exit ();nsim_dev_exit (); -debugfs_remove_recursive (nsim_ddir); }module_init (nsim_module_init);
drivers/net/netdevsim/netdevsim.h +1 -0
@@ -134,6 +134,7 @@ struct nsim_dev {struct nsim_bus_dev *nsim_bus_dev;struct nsim_fib_data *fib_data;struct dentry *ddir; +struct dentry *ports_ddir;struct bpf_offload_dev *bpf_dev;bool bpf_bind_accept;u32 bpf_bind_verifier_delay;
tools/testing/selftests/bpf/test_offload.py +3 -1
@@ -306,6 +306,8 @@ class DebugfsDir: _, out = cmd('ls ' + path) for f in out.split(): + if f == "ports": + continue p = os.path.join(path, f) if os.path.isfile(p): _, out = cmd('cat %s/%s' % (path, f))
@@ -334,7 +336,7 @@ class NetdevSim: self.ns = "" - self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname']) + self.dfs_dir = '/sys/kernel/debug/netdevsim/netdevsim0/ports/0/' self.dev_dir = self.dfs_dir + '/dev/' self.dfs_refresh()
tools/testing/selftests/net/rtnetlink.sh +1 -1
@@ -697,7 +697,7 @@ kci_test_ipsec_offload() srcip=192.168.123.3 dstip=192.168.123.4 dev=simx1 - sysfsd=/sys/kernel/debug/netdevsim/$dev + sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/ sysfsf=$sysfsd/ipsec # setup netdevsim since dummydev doesn't have offload support
Signature · 1 line
2.17.2
RFC PATCH 13/15 netdevsim: implement dev probe/remove skeleton with port initialization
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Implement netdevsim bus probing of netdevsim devices. For every probed device create a devlink instance. According to the user-passed value, create a number of ports represented by devlink port instances.
--- drivers/net/netdevsim/bus.c | 29 ++++++++ drivers/net/netdevsim/dev.c | 115 ++++++++++++++++++++++++++---- drivers/net/netdevsim/netdev.c | 15 ++-- drivers/net/netdevsim/netdevsim.h | 14 +++- 4 files changed, 144 insertions(+), 29 deletions(-)
drivers/net/netdevsim/bus.c +29 -0
@@ -194,6 +194,21 @@ static struct attribute *nsim_bus_attrs[] = { };ATTRIBUTE_GROUPS (nsim_bus); +static int nsim_bus_probe (struct device *dev) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); + +return nsim_dev_probe (nsim_bus_dev); +} + +static int nsim_bus_remove (struct device *dev) +{ +struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); + +nsim_dev_remove (nsim_bus_dev); +return 0 ; +} +int nsim_num_vf (struct device *dev) {struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev);
@@ -205,6 +220,8 @@ static struct bus_type nsim_bus = { .name = DRV_NAME, .dev_name = DRV_NAME, .bus_groups = nsim_bus_groups, + .probe = nsim_bus_probe, + .remove = nsim_bus_remove, .num_vf = nsim_num_vf, };
@@ -238,6 +255,18 @@ struct nsim_bus_dev *nsim_bus_dev_new(unsigned int id, unsigned int port_count)return ERR_PTR (err); } +struct nsim_bus_dev *nsim_bus_dev_new_with_ns (struct netdevsim *ns) +{ +struct nsim_bus_dev *nsim_bus_dev; + +dev_hold (ns->netdev); +rtnl_unlock (); + nsim_bus_dev =nsim_bus_dev_new (~0 ,0 ); +rtnl_lock (); +dev_put (ns->netdev); +return nsim_bus_dev; +} +void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev) {device_unregister (&nsim_bus_dev->dev);
drivers/net/netdevsim/dev.c +100 -15
144 lines not on this page · raw message
drivers/net/netdevsim/netdev.c +4 -11
@@ -74,7 +74,6 @@ static void nsim_free(struct net_device *dev) {struct netdevsim *ns =netdev_priv (dev); -nsim_dev_destroy (ns->nsim_dev);nsim_bus_dev_del (ns->nsim_bus_dev);/* netdev and vf state will be freed out of device_release() */ }
@@ -364,26 +363,20 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,struct netdevsim *ns =netdev_priv (dev);int err; - ns->nsim_bus_dev =nsim_bus_dev_new (~0 ,0 ); + ns->netdev = dev; + ns->nsim_bus_dev =nsim_bus_dev_new_with_ns (ns);if (IS_ERR (ns->nsim_bus_dev))return PTR_ERR (ns->nsim_bus_dev);SET_NETDEV_DEV (dev, &ns->nsim_bus_dev->dev); - ns->netdev = dev; - ns->nsim_dev =nsim_dev_create_with_ns (ns->nsim_bus_dev, ns); -if (IS_ERR (ns->nsim_dev)) { - err =PTR_ERR (ns->nsim_dev); - goto err_dev_del; - } + ns->nsim_dev =dev_get_drvdata (&ns->nsim_bus_dev->dev); err =register_netdevice (dev);if (err) - goto err_dev_destroy; + goto err_dev_del;return 0 ; -err_dev_destroy: -nsim_dev_destroy (ns->nsim_dev); err_dev_del:nsim_bus_dev_del (ns->nsim_bus_dev);return err;
drivers/net/netdevsim/netdevsim.h +11 -3
@@ -18,6 +18,7 @@#include <linux/list.h> #include <linux/netdevice.h> #include <linux/u64_stats_sync.h> +#include <net/devlink.h> #include <net/xdp.h> #define DRV_NAME "netdevsim"
@@ -130,6 +131,12 @@ enum nsim_resource_id { NSIM_RESOURCE_IPV6_FIB_RULES, }; +struct nsim_dev_port { +struct devlink_port devlink_port; +unsigned int port_index; +struct dentry *ddir; +}; +struct nsim_dev {struct nsim_bus_dev *nsim_bus_dev;struct nsim_fib_data *fib_data;
@@ -143,13 +150,13 @@ struct nsim_dev {struct list_head bpf_bound_progs;struct list_head bpf_bound_maps;struct netdev_phys_item_id switch_id; +struct nsim_dev_port ports[0 ]; }; -struct nsim_dev *nsim_dev_create_with_ns (struct nsim_bus_dev *nsim_bus_dev, -struct netdevsim *ns); -void nsim_dev_destroy (struct nsim_dev *nsim_dev);int nsim_dev_init (void );void nsim_dev_exit (void ); +int nsim_dev_probe (struct nsim_bus_dev *nsim_bus_dev); +void nsim_dev_remove (struct nsim_bus_dev *nsim_bus_dev);struct nsim_fib_data *nsim_fib_create (void );void nsim_fib_destroy (struct nsim_fib_data *fib_data);
@@ -200,6 +207,7 @@ struct nsim_bus_dev { };struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id,unsigned int port_count); +struct nsim_bus_dev *nsim_bus_dev_new_with_ns (struct netdevsim *ns);void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev);int nsim_bus_init (void );void nsim_bus_exit (void );
Signature · 1 line
2.17.2
RFC PATCH 14/15 netdevsim: move netdev creation/destruction to dev probe
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Remove the existing way to create netdevsim over rtnetlink and move the netdev creation/destruction to dev probe, so for every probed port, a netdevsim-netdev instance is created.
Adjust selftests to work with new interface.
--- drivers/net/netdevsim/bpf.c | 13 ++- drivers/net/netdevsim/bus.c | 25 ++-- drivers/net/netdevsim/dev.c | 14 ++- drivers/net/netdevsim/ipsec.c | 3 +- drivers/net/netdevsim/netdev.c | 138 ++++++++--------------- drivers/net/netdevsim/netdevsim.h | 11 +- tools/testing/selftests/net/rtnetlink.sh | 6 +- 7 files changed, 89 insertions(+), 121 deletions(-)
drivers/net/netdevsim/bpf.c +7 -6
@@ -612,6 +612,7 @@ void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev)int nsim_bpf_init (struct netdevsim *ns) { +struct dentry *ddir = ns->nsim_dev_port->ddir;int err; err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev,
@@ -619,23 +620,23 @@ int nsim_bpf_init(struct netdevsim *ns)if (err)return err; -debugfs_create_u32 ("bpf_offloaded_id" ,0400 , ns->ddir, +debugfs_create_u32 ("bpf_offloaded_id" ,0400 , ddir, &ns->bpf_offloaded_id); ns->bpf_tc_accept = true; -debugfs_create_bool ("bpf_tc_accept" ,0600 , ns->ddir, +debugfs_create_bool ("bpf_tc_accept" ,0600 , ddir, &ns->bpf_tc_accept); -debugfs_create_bool ("bpf_tc_non_bound_accept" ,0600 , ns->ddir, +debugfs_create_bool ("bpf_tc_non_bound_accept" ,0600 , ddir, &ns->bpf_tc_non_bound_accept); ns->bpf_xdpdrv_accept = true; -debugfs_create_bool ("bpf_xdpdrv_accept" ,0600 , ns->ddir, +debugfs_create_bool ("bpf_xdpdrv_accept" ,0600 , ddir, &ns->bpf_xdpdrv_accept); ns->bpf_xdpoffload_accept = true; -debugfs_create_bool ("bpf_xdpoffload_accept" ,0600 , ns->ddir, +debugfs_create_bool ("bpf_xdpoffload_accept" ,0600 , ddir, &ns->bpf_xdpoffload_accept); ns->bpf_map_accept = true; -debugfs_create_bool ("bpf_map_accept" ,0600 , ns->ddir, +debugfs_create_bool ("bpf_map_accept" ,0600 , ddir, &ns->bpf_map_accept);return 0 ;
drivers/net/netdevsim/bus.c +9 -16
@@ -117,6 +117,9 @@ static struct device_type nsim_bus_dev_type = { .release = nsim_bus_dev_release, }; +static struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id, +unsigned int port_count); +static ssize_t new_device_store (struct bus_type *bus,const char *buf,size_t count) {
@@ -152,6 +155,8 @@ static ssize_t new_device_store(struct bus_type *bus, const char *buf, }static BUS_ATTR_WO (new_device); +static void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev); +static ssize_t del_device_store (struct bus_type *bus,const char *buf,size_t count) {
@@ -225,7 +230,8 @@ static struct bus_type nsim_bus = { .num_vf = nsim_num_vf, }; -struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id,unsigned int port_count) +static struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id, +unsigned int port_count) {struct nsim_bus_dev *nsim_bus_dev;int err;
@@ -234,8 +240,7 @@ struct nsim_bus_dev *nsim_bus_dev_new(unsigned int id, unsigned int port_count)if (!nsim_bus_dev)return ERR_PTR (-ENOMEM ); - err =ida_alloc_range (&nsim_bus_dev_ids, - id == ~0 ?0 : id, id,GFP_KERNEL ); + err =ida_alloc_range (&nsim_bus_dev_ids, id, id,GFP_KERNEL );if (err <0 ) goto err_nsim_bus_dev_free; nsim_bus_dev->dev.id = err;
@@ -255,19 +260,7 @@ struct nsim_bus_dev *nsim_bus_dev_new(unsigned int id, unsigned int port_count)return ERR_PTR (err); } -struct nsim_bus_dev *nsim_bus_dev_new_with_ns (struct netdevsim *ns) -{ -struct nsim_bus_dev *nsim_bus_dev; - -dev_hold (ns->netdev); -rtnl_unlock (); - nsim_bus_dev =nsim_bus_dev_new (~0 ,0 ); -rtnl_lock (); -dev_put (ns->netdev); -return nsim_bus_dev; -} - -void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev) +static void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev) {device_unregister (&nsim_bus_dev->dev);ida_free (&nsim_bus_dev_ids, nsim_bus_dev->dev.id);
drivers/net/netdevsim/dev.c +13 -1
@@ -275,7 +275,7 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev,return ERR_PTR (err); } -void nsim_dev_destroy (struct nsim_dev *nsim_dev) +static void nsim_dev_destroy (struct nsim_dev *nsim_dev) {struct devlink *devlink =priv_to_devlink (nsim_dev);
@@ -307,8 +307,18 @@ static int nsim_dev_port_init(struct nsim_dev *nsim_dev, err =nsim_dev_port_debugfs_init (nsim_dev, nsim_dev_port);if (err) goto err_dl_port_unregister; + + nsim_dev_port->ns =nsim_create (nsim_dev, nsim_dev_port); +if (IS_ERR (nsim_dev_port->ns)) { + err =PTR_ERR (nsim_dev_port->ns); + goto err_port_debugfs_exit; + } + +devlink_port_type_eth_set (devlink_port, nsim_dev_port->ns->netdev);return 0 ; +err_port_debugfs_exit: +nsim_dev_port_debugfs_exit (nsim_dev_port); err_dl_port_unregister:devlink_port_unregister (devlink_port);return err;
@@ -320,6 +330,8 @@ static void nsim_dev_port_exit(struct nsim_dev *nsim_dev,struct nsim_dev_port *nsim_dev_port = &nsim_dev->ports[port_index];struct devlink_port *devlink_port = &nsim_dev_port->devlink_port; +devlink_port_type_clear (devlink_port); +nsim_destroy (nsim_dev_port->ns);nsim_dev_port_debugfs_exit (nsim_dev_port);devlink_port_unregister (devlink_port); }
drivers/net/netdevsim/ipsec.c +2 -1
@@ -283,7 +283,8 @@ void nsim_ipsec_init(struct netdevsim *ns) ns->netdev->features |=NSIM_ESP_FEATURES ; ns->netdev->hw_enc_features |=NSIM_ESP_FEATURES ; - ns->ipsec.pfile =debugfs_create_file ("ipsec" ,0400 , ns->ddir, ns, + ns->ipsec.pfile =debugfs_create_file ("ipsec" ,0400 , + ns->nsim_dev_port->ddir, ns, &ipsec_dbg_fops); }
drivers/net/netdevsim/netdev.c +49 -89
183 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +6 -5
@@ -51,6 +51,7 @@ struct nsim_ipsec {struct netdevsim {struct net_device *netdev;struct nsim_dev *nsim_dev; +struct nsim_dev_port *nsim_dev_port;u64 tx_packets;u64 tx_bytes;
@@ -58,8 +59,6 @@ struct netdevsim {struct nsim_bus_dev *nsim_bus_dev; -struct dentry *ddir; -struct bpf_prog *bpf_offloaded;u32 bpf_offloaded_id;
@@ -75,6 +74,10 @@ struct netdevsim {struct nsim_ipsec ipsec; }; +struct netdevsim *nsim_create (struct nsim_dev *nsim_dev, +struct nsim_dev_port *nsim_dev_port); +void nsim_destroy (struct netdevsim *ns); +#ifdef CONFIG_BPF_SYSCALL int nsim_bpf_dev_init (struct nsim_dev *nsim_dev);void nsim_bpf_dev_exit (struct nsim_dev *nsim_dev);
@@ -135,6 +138,7 @@ struct nsim_dev_port {struct devlink_port devlink_port;unsigned int port_index;struct dentry *ddir; +struct netdevsim *ns; };struct nsim_dev {
@@ -206,8 +210,5 @@ struct nsim_bus_dev {struct nsim_vf_config *vfconfigs; }; -struct nsim_bus_dev *nsim_bus_dev_new (unsigned int id,unsigned int port_count); -struct nsim_bus_dev *nsim_bus_dev_new_with_ns (struct netdevsim *ns); -void nsim_bus_dev_del (struct nsim_bus_dev *nsim_bus_dev);int nsim_bus_init (void );void nsim_bus_exit (void );
tools/testing/selftests/net/rtnetlink.sh +3 -3
@@ -696,7 +696,7 @@ kci_test_ipsec_offload() algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128" srcip=192.168.123.3 dstip=192.168.123.4 - dev=simx1 + dev=netdevsim0p1 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/ sysfsf=$sysfsd/ipsec
@@ -708,7 +708,8 @@ kci_test_ipsec_offload() return 1 fi - ip link add $dev type netdevsim + echo "0" > /sys/bus/netdevsim/new_device + sleep 0.2 ip addr add $srcip dev $dev ip link set $dev up if [ ! -d $sysfsd ] ; then
@@ -781,7 +782,6 @@ EOF fi # clean up any leftovers - ip link del $dev rmmod netdevsim if [ $ret -ne 0 ]; then
Signature · 1 line
2.17.2
RFC PATCH 15/15 netdevsim: implement ndo_get_devlink_port
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Implement ndo_get_devlink_port and allow switch_id and port_name to be handled by devlink.
--- drivers/net/netdevsim/netdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/netdevsim/netdev.c +8 -0
@@ -245,6 +245,13 @@ nsim_set_features(struct net_device *dev, netdev_features_t features)return 0 ; } +static struct devlink_port *nsim_get_devlink_port (struct net_device *dev) +{ +struct netdevsim *ns =netdev_priv (dev); + +return &ns->nsim_dev_port->devlink_port; +} +static const struct net_device_ops nsim_netdev_ops = { .ndo_start_xmit = nsim_start_xmit, .ndo_set_rx_mode = nsim_set_rx_mode,
@@ -263,6 +270,7 @@ static const struct net_device_ops nsim_netdev_ops = { .ndo_setup_tc = nsim_setup_tc, .ndo_set_features = nsim_set_features, .ndo_bpf = nsim_bpf, + .ndo_get_devlink_port = nsim_get_devlink_port, };static void nsim_setup (struct net_device *dev)
Signature · 1 line
2.17.2
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the model of netdevsim is a bit odd in multiple ways.
1) devlink instance is not in any way related with actual netdevsim netdevices. Instead, it is created per-namespace.
2) multi-port netdevsim device is done using "link" attribute.
3) netdevsim bus is there only to have something to bind the netdev to, it really does not act as a bus.
Nope, it's there to expose SR-IOV ops :)
Quoted 5 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
Quoted 8 lines
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
echo "10 4" >
/sys/bus/netdevsim/new_device
I really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Quoted 11 lines
Then devlink shows this:
$ devlink dev netdevsim/netdevsim10$ devlink port netdevsim/netdevsim10/0: type eth netdev netdevsim10p1 flavour physical netdevsim/netdevsim10/1: type eth netdev netdevsim10p2 flavour physical netdevsim/netdevsim10/2: type eth netdev netdevsim10p3 flavour physical netdevsim/netdevsim10/3: type eth netdev netdevsim10p4 flavour physical
Quoted 5 lines
Debugfs topology is also adjusted a bit. The rest stays the same as before.
TODO:
- teach udev to rename netdevsim netdevices similarly to pci netdevices
So we can test udev as well?
Quoted 1 line
- fix
tools/testing/selftests/bpf/test_offload.pyto work with new iface
That'd step 0 :)
BTW are you testing all this with the various sysfs/kobject debug checks? I don't remember all the deets now, but there were certainly ordering considerations coming from there.
Quoted 11 lines · Mon, Apr 15, 2019 at 09:27:09PM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the model of netdevsim is a bit odd in multiple ways.
1) devlink instance is not in any way related with actual netdevsim netdevices. Instead, it is created per-namespace.
2) multi-port netdevsim device is done using "link" attribute.
3) netdevsim bus is there only to have something to bind the netdev to, it really does not act as a bus.Nope, it's there to expose SR-IOV ops :)
They are not on the bus, they are on the device.
Quoted 13 lines
Quoted 13 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 4 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
The reason is the then the address, devlink handles and netdev names are predictable. If it would be auto-generated, how could you know what did you just created?
Quoted 5 lines
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
So what do you suggest?
Quoted 12 lines
Quoted 12 lines
Then devlink shows this:
$ devlink dev netdevsim/netdevsim10$ devlink port netdevsim/netdevsim10/0: type eth netdev netdevsim10p1 flavour physical netdevsim/netdevsim10/1: type eth netdev netdevsim10p2 flavour physical netdevsim/netdevsim10/2: type eth netdev netdevsim10p3 flavour physical netdevsim/netdevsim10/3: type eth netdev netdevsim10p4 flavour physical
Quoted 7 lines
Quoted 5 lines
Debugfs topology is also adjusted a bit. The rest stays the same as before.
TODO:
- teach udev to rename netdevsim netdevices similarly to pci netdevicesSo we can test udev as well?
https://github.com/systemd/systemd/pull/12328
Quoted 8 lines
Quoted 2 lines
- fix
tools/testing/selftests/bpf/test_offload.pyto work with new ifaceThat'd step 0 :)
BTW are you testing all this with the various sysfs/kobject debug checks? I don't remember all the deets now, but there were certainly ordering considerations coming from there.
Yes.
Quoted 11 lines · Jiri Pirko
Quoted 10 lines · Mon, Apr 15, 2019 at 09:27:09PM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the model of netdevsim is a bit odd in multiple ways.
1) devlink instance is not in any way related with actual netdevsim netdevices. Instead, it is created per-namespace.
2) multi-port netdevsim device is done using "link" attribute.
3) netdevsim bus is there only to have something to bind the netdev to, it really does not act as a bus.
Quoted 3 lines
Quoted 1 line
Nope, it's there to expose SR-IOV ops :)
They are not on the bus, they are on the device.
Right, I'm just explaining why there is a device in the first place.
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 4 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
The reason is the then the address, devlink handles and netdev names are predictable. If it would be auto-generated, how could you know what did you just created?
Quoted 6 lines
Quoted 4 lines
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
So what do you suggest?
I haven't looked at this in detail. One quick idea is perhaps to remember what ID was used after the write on the file descriptor, and then next read would return the ID?
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Then devlink shows this:
$ devlink dev netdevsim/netdevsim10$ devlink port netdevsim/netdevsim10/0: type eth netdev netdevsim10p1 flavour physical netdevsim/netdevsim10/1: type eth netdev netdevsim10p2 flavour physical netdevsim/netdevsim10/2: type eth netdev netdevsim10p3 flavour physical netdevsim/netdevsim10/3: type eth netdev netdevsim10p4 flavour physicalQuoted 7 lines
Quoted 5 lines
Debugfs topology is also adjusted a bit. The rest stays the same as before.
TODO:
- teach udev to rename netdevsim netdevices similarly to pci netdevicesSo we can test udev as well?
https://github.com/systemd/systemd/pull/12328
Quoted 2 lines
Quoted 1 line
- fix
tools/testing/selftests/bpf/test_offload.pyto work with new iface
Quoted 7 lines
Quoted 5 lines
That'd step 0 :)
BTW are you testing all this with the various sysfs/kobject debug checks? I don't remember all the deets now, but there were certainly ordering considerations coming from there.
Yes.
Cool :)
Quoted 24 lines · Mon, Apr 15, 2019 at 09:27:09PM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the model of netdevsim is a bit odd in multiple ways.
1) devlink instance is not in any way related with actual netdevsim netdevices. Instead, it is created per-namespace.
2) multi-port netdevsim device is done using "link" attribute.
3) netdevsim bus is there only to have something to bind the netdev to, it really does not act as a bus.Nope, it's there to expose SR-IOV ops :)
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 7 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one
Care to define "atomically" here? It is done in a very similar way to how it is done in mlxsw for example. Same flows.
Quoted 2 lines
by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Same here. Not sure where do you see the differences.
Also, I plan to implement port splitting in follow-up patchset. All flows are there as well.
Quoted 27 lines
Quoted 12 lines
Then devlink shows this:
$ devlink dev netdevsim/netdevsim10$ devlink port netdevsim/netdevsim10/0: type eth netdev netdevsim10p1 flavour physical netdevsim/netdevsim10/1: type eth netdev netdevsim10p2 flavour physical netdevsim/netdevsim10/2: type eth netdev netdevsim10p3 flavour physical netdevsim/netdevsim10/3: type eth netdev netdevsim10p4 flavour physicalQuoted 5 lines
Debugfs topology is also adjusted a bit. The rest stays the same as before.
TODO:
- teach udev to rename netdevsim netdevices similarly to pci netdevicesSo we can test udev as well?
Quoted 1 line
- fix
tools/testing/selftests/bpf/test_offload.pyto work with new ifaceThat'd step 0 :)
BTW are you testing all this with the various sysfs/kobject debug checks? I don't remember all the deets now, but there were certainly ordering considerations coming from there.
Quoted 20 lines · Jiri Pirko
Quoted 12 lines
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 7 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one
Quoted 8 lines
Care to define "atomically" here? It is done in a very similar way to how it is done in mlxsw for example. Same flows.
Quoted 2 lines
by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Same here. Not sure where do you see the differences.
The difference is that today I can do this:
create a netdevsim1 with shared dev 1
create some state associated with shared dev 1
create a netdevsim2 with shared dev 1
check if all the shared dev 1 state created for netdevsim1 is visible
via netdevsim2
destroy netdevsim1
check the shared dev 1 state again
If I say "give me 2 ports" from the start, that makes the testing (which is the whole point of this code) harder.
Quoted 2 lines
Also, I plan to implement port splitting in follow-up patchset. All flows are there as well.
Sure, let's just be clear that we won't be merging an ABI that has just a netdevsim implementation, right? I have some reservations about the "port splitting" or device slicing, which should be discussed over real code, not netdevsim.
Quoted 30 lines · Tue, Apr 16, 2019 at 08:04:59PM CEST, [email protected] wrote:
Quoted 20 lines · Jiri Pirko
Quoted 12 lines
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 7 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one
Quoted 8 lines
Care to define "atomically" here? It is done in a very similar way to how it is done in mlxsw for example. Same flows.
Quoted 2 lines
by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Same here. Not sure where do you see the differences.
Quoted 7 lines
The difference is that today I can do this:
create a netdevsim1 with shared dev 1
create some state associated with shared dev 1
create a netdevsim2 with shared dev 1
check if all the shared dev 1 state created for netdevsim1 is visible
via netdevsim2
Hmm, you are testing netdevsim implementation then, not the kernel interfaces. What is the point of testing netdevsim?
Quoted 11 lines
destroy netdevsim1
check the shared dev 1 state againIf I say "give me 2 ports" from the start, that makes the testing (which is the whole point of this code) harder.
Quoted 2 lines
Also, I plan to implement port splitting in follow-up patchset. All flows are there as well.
Sure, let's just be clear that we won't be merging an ABI that has just a netdevsim implementation, right? I have some reservations about the
So what do you suggest? Allow to somehow add and remove ports during test? You can already do that with VFs. Do you want to do that with netdevsim "physical" ports? If yes, how? I can imagine to extend devlink port api with something like:
$ sudo devlink dev netdevsim/netdevsim0 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eth0 flavour physical
$ sudo devlink dev port add netdevsim/netdevsim0 index 22 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eni0p1 flavour physical netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physical
$ sudo devlink port del netdevsim/netdevsim0/0 $ sudo devlink port netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physical
But I see only usecase for this extension for netdevsim, not for real devices..
Quoted 2 lines
"port splitting" or device slicing, which should be discussed over real code, not netdevsim.
Quoted 33 lines · Jiri Pirko
Quoted 32 lines · Tue, Apr 16, 2019 at 08:04:59PM CEST, [email protected] wrote:
Quoted 20 lines · Jiri Pirko
Quoted 12 lines
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 7 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one
Quoted 8 lines
Care to define "atomically" here? It is done in a very similar way to how it is done in mlxsw for example. Same flows.
Quoted 2 lines
by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Same here. Not sure where do you see the differences.
The difference is that today I can do this:
Quoted 8 lines
Quoted 5 lines
create a netdevsim1 with shared dev 1
create some state associated with shared dev 1
create a netdevsim2 with shared dev 1
check if all the shared dev 1 state created for netdevsim1 is visible
via netdevsim2Hmm, you are testing netdevsim implementation then, not the kernel interfaces. What is the point of testing netdevsim?
BPF offload tries to leave as much code as possible in the core, and make the drivers simple. I'm testing whether the core reacts correctly, netdevsim just calls register/unregister.
Quoted 27 lines
Quoted 11 lines
destroy netdevsim1
check the shared dev 1 state againIf I say "give me 2 ports" from the start, that makes the testing (which is the whole point of this code) harder.
Quoted 2 lines
Also, I plan to implement port splitting in follow-up patchset. All flows are there as well.
Sure, let's just be clear that we won't be merging an ABI that has just a netdevsim implementation, right? I have some reservations about the
So what do you suggest? Allow to somehow add and remove ports during test? You can already do that with VFs. Do you want to do that with netdevsim "physical" ports? If yes, how? I can imagine to extend devlink port api with something like:
$ sudo devlink dev netdevsim/netdevsim0 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eth0 flavour physical$ sudo devlink dev port add netdevsim/netdevsim0 index 22 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eni0p1 flavour physical netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physical
Quoted 6 lines
$ sudo devlink port del netdevsim/netdevsim0/0 $ sudo devlink port netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physicalBut I see only usecase for this extension for netdevsim, not for real devices..
Hm.. I'm getting lost, sorry, I'm probably confusing myself here..
Netdevsim is supposed to test real, existing kernel interfaces and core code. What we do today with linking based on netdevs is quite simple and works very well for the BPF offload tests.
If you want to test some devlink code, that's also real, perfect.
For BPF tests we want the ability to add and remove netdevs to a sdev during tests, yes. That ability cannot be lost.
Quoted 2 lines
Quoted 2 lines
"port splitting" or device slicing, which should be discussed over real code, not netdevsim.
Quoted 83 lines · Thu, Apr 18, 2019 at 07:07:48PM CEST, [email protected] wrote:
Quoted 33 lines · Jiri Pirko
Quoted 32 lines · Tue, Apr 16, 2019 at 08:04:59PM CEST, [email protected] wrote:
Quoted 20 lines · Jiri Pirko
Quoted 12 lines
Quoted 12 lines
4) netdevsim instances are created by "ip link add" which is great for soft devices with no hw backend. The rtnl core allocates netdev and calls into driver holding rtnl mutex. For hw-backed devices, this flow is wrong as it breaks order in which things are done.
This patchset adjust netdevsim to fix all above.
In order to support proper devlink and devlink port instances and to be able to emulate real devices, there is need to implement bus probe and instantiate everything from there. User can specify device id and port count to be instantianted. For example:
Quoted 7 lines
Quoted 1 line
echo "10 4" >
/sys/bus/netdevsim/new_deviceI really don't like the design where ID has to be allocated by user space. It's a step back.
I also dislike declaring ports from the start. In real drivers ports are never "atomically" registered, they are crated and destroyed one
Quoted 8 lines
Care to define "atomically" here? It is done in a very similar way to how it is done in mlxsw for example. Same flows.
Quoted 2 lines
by one, and a lot of races/UAFs/bugs lie in those small periods of time where one netdev got unregistered, but other are still around...
Same here. Not sure where do you see the differences.
The difference is that today I can do this:
Quoted 8 lines
Quoted 5 lines
create a netdevsim1 with shared dev 1
create some state associated with shared dev 1
create a netdevsim2 with shared dev 1
check if all the shared dev 1 state created for netdevsim1 is visible
via netdevsim2Hmm, you are testing netdevsim implementation then, not the kernel interfaces. What is the point of testing netdevsim?
BPF offload tries to leave as much code as possible in the core, and make the drivers simple. I'm testing whether the core reacts correctly, netdevsim just calls register/unregister.
Quoted 27 lines
Quoted 11 lines
destroy netdevsim1
check the shared dev 1 state againIf I say "give me 2 ports" from the start, that makes the testing (which is the whole point of this code) harder.
Quoted 2 lines
Also, I plan to implement port splitting in follow-up patchset. All flows are there as well.
Sure, let's just be clear that we won't be merging an ABI that has just a netdevsim implementation, right? I have some reservations about the
So what do you suggest? Allow to somehow add and remove ports during test? You can already do that with VFs. Do you want to do that with netdevsim "physical" ports? If yes, how? I can imagine to extend devlink port api with something like:
$ sudo devlink dev netdevsim/netdevsim0 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eth0 flavour physical$ sudo devlink dev port add netdevsim/netdevsim0 index 22 $ sudo devlink port netdevsim/netdevsim0/0: type eth netdev eni0p1 flavour physical netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physicalQuoted 6 lines
$ sudo devlink port del netdevsim/netdevsim0/0 $ sudo devlink port netdevsim/netdevsim0/22: type eth netdev eni0p23 flavour physicalBut I see only usecase for this extension for netdevsim, not for real devices..
Hm.. I'm getting lost, sorry, I'm probably confusing myself here..
Quoted 8 lines
Netdevsim is supposed to test real, existing kernel interfaces and core code. What we do today with linking based on netdevs is quite simple and works very well for the BPF offload tests.
If you want to test some devlink code, that's also real, perfect.
For BPF tests we want the ability to add and remove netdevs to a sdev during tests, yes. That ability cannot be lost.
Yeah, but since the api is changing, the original approach of using IFLA_LINK cannot be used anymore. Not to mention is is abuse of the API from the very beginning. You want to add/del ports during lifetime, I'm trying to find interface. Basically whe have two options:
1) devlink extension I suggested above
2) sysfs files to add/del ports. Similar to "new_device" and "del_device".
I like the idea of having 2) better, the reason is this is very speficic to netdevsim and not really applicable on real devices.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
"port splitting" or device slicing, which should be discussed over real code, not netdevsim.
Quoted 19 lines · Jiri Pirko
Quoted 10 lines
Hm.. I'm getting lost, sorry, I'm probably confusing myself here..
Netdevsim is supposed to test real, existing kernel interfaces and core code. What we do today with linking based on netdevs is quite simple and works very well for the BPF offload tests.
If you want to test some devlink code, that's also real, perfect.
For BPF tests we want the ability to add and remove netdevs to a sdev during tests, yes. That ability cannot be lost.
Yeah, but since the api is changing, the original approach of using
IFLA_LINKcannot be used anymore. Not to mention is is abuse of the API from the very beginning. You want to add/del ports during lifetime, I'm trying to find interface. Basically whe have two options:
1) devlink extension I suggested above
2) sysfs files to add/del ports. Similar to "new_device" and "del_device".
Quoted 2 lines
I like the idea of having 2) better, the reason is this is very speficic to netdevsim and not really applicable on real devices.
Sure, if custom sysfs API is any better than the use of IFLA_LINK in a test mock up, go for it.
Creating a custom devlink ABI for a test mockup netdev seems like a bad idea.