提交 d6d60713 编写于 作者: J Jakub Kicinski 提交者: Daniel Borkmann

netdevsim: associate bound programs with shared dev

Move bound program information from netdevsim to shared sub-object,
as programs will soon be shared between netdevs of the same ASIC.
Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: NQuentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
上级 eeeaaf18
...@@ -238,8 +238,8 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) ...@@ -238,8 +238,8 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
state->state = "verify"; state->state = "verify";
/* Program id is not populated yet when we create the state. */ /* Program id is not populated yet when we create the state. */
sprintf(name, "%u", ns->prog_id_gen++); sprintf(name, "%u", ns->sdev->prog_id_gen++);
state->ddir = debugfs_create_dir(name, ns->ddir_bpf_bound_progs); state->ddir = debugfs_create_dir(name, ns->sdev->ddir_bpf_bound_progs);
if (IS_ERR_OR_NULL(state->ddir)) { if (IS_ERR_OR_NULL(state->ddir)) {
kfree(state); kfree(state);
return -ENOMEM; return -ENOMEM;
...@@ -250,7 +250,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) ...@@ -250,7 +250,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
&state->state, &nsim_bpf_string_fops); &state->state, &nsim_bpf_string_fops);
debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded); debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded);
list_add_tail(&state->l, &ns->bpf_bound_progs); list_add_tail(&state->l, &ns->sdev->bpf_bound_progs);
prog->aux->offload->dev_priv = state; prog->aux->offload->dev_priv = state;
...@@ -497,7 +497,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap) ...@@ -497,7 +497,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
} }
offmap->dev_ops = &nsim_bpf_map_ops; offmap->dev_ops = &nsim_bpf_map_ops;
list_add_tail(&nmap->l, &ns->bpf_bound_maps); list_add_tail(&nmap->l, &ns->sdev->bpf_bound_maps);
return 0; return 0;
...@@ -582,8 +582,15 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf) ...@@ -582,8 +582,15 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
int nsim_bpf_init(struct netdevsim *ns) int nsim_bpf_init(struct netdevsim *ns)
{ {
INIT_LIST_HEAD(&ns->bpf_bound_progs); if (ns->sdev->refcnt == 1) {
INIT_LIST_HEAD(&ns->bpf_bound_maps); INIT_LIST_HEAD(&ns->sdev->bpf_bound_progs);
INIT_LIST_HEAD(&ns->sdev->bpf_bound_maps);
ns->sdev->ddir_bpf_bound_progs =
debugfs_create_dir("bpf_bound_progs", ns->sdev->ddir);
if (IS_ERR_OR_NULL(ns->sdev->ddir_bpf_bound_progs))
return -ENOMEM;
}
debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir, debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir,
&ns->bpf_offloaded_id); &ns->bpf_offloaded_id);
...@@ -593,10 +600,6 @@ int nsim_bpf_init(struct netdevsim *ns) ...@@ -593,10 +600,6 @@ int nsim_bpf_init(struct netdevsim *ns)
&ns->bpf_bind_accept); &ns->bpf_bind_accept);
debugfs_create_u32("bpf_bind_verifier_delay", 0600, ns->ddir, debugfs_create_u32("bpf_bind_verifier_delay", 0600, ns->ddir,
&ns->bpf_bind_verifier_delay); &ns->bpf_bind_verifier_delay);
ns->ddir_bpf_bound_progs =
debugfs_create_dir("bpf_bound_progs", ns->ddir);
if (IS_ERR_OR_NULL(ns->ddir_bpf_bound_progs))
return -ENOMEM;
ns->bpf_tc_accept = true; ns->bpf_tc_accept = true;
debugfs_create_bool("bpf_tc_accept", 0600, ns->ddir, debugfs_create_bool("bpf_tc_accept", 0600, ns->ddir,
...@@ -619,9 +622,12 @@ int nsim_bpf_init(struct netdevsim *ns) ...@@ -619,9 +622,12 @@ int nsim_bpf_init(struct netdevsim *ns)
void nsim_bpf_uninit(struct netdevsim *ns) void nsim_bpf_uninit(struct netdevsim *ns)
{ {
WARN_ON(!list_empty(&ns->bpf_bound_progs));
WARN_ON(!list_empty(&ns->bpf_bound_maps));
WARN_ON(ns->xdp.prog); WARN_ON(ns->xdp.prog);
WARN_ON(ns->xdp_hw.prog); WARN_ON(ns->xdp_hw.prog);
WARN_ON(ns->bpf_offloaded); WARN_ON(ns->bpf_offloaded);
if (ns->sdev->refcnt == 1) {
WARN_ON(!list_empty(&ns->sdev->bpf_bound_progs));
WARN_ON(!list_empty(&ns->sdev->bpf_bound_maps));
}
} }
...@@ -35,6 +35,12 @@ struct netdevsim_shared_dev { ...@@ -35,6 +35,12 @@ struct netdevsim_shared_dev {
u32 switch_id; u32 switch_id;
struct dentry *ddir; struct dentry *ddir;
struct dentry *ddir_bpf_bound_progs;
u32 prog_id_gen;
struct list_head bpf_bound_progs;
struct list_head bpf_bound_maps;
}; };
#define NSIM_IPSEC_MAX_SA_COUNT 33 #define NSIM_IPSEC_MAX_SA_COUNT 33
...@@ -79,12 +85,8 @@ struct netdevsim { ...@@ -79,12 +85,8 @@ struct netdevsim {
struct xdp_attachment_info xdp; struct xdp_attachment_info xdp;
struct xdp_attachment_info xdp_hw; struct xdp_attachment_info xdp_hw;
u32 prog_id_gen;
bool bpf_bind_accept; bool bpf_bind_accept;
u32 bpf_bind_verifier_delay; u32 bpf_bind_verifier_delay;
struct dentry *ddir_bpf_bound_progs;
struct list_head bpf_bound_progs;
bool bpf_tc_accept; bool bpf_tc_accept;
bool bpf_tc_non_bound_accept; bool bpf_tc_non_bound_accept;
...@@ -92,7 +94,6 @@ struct netdevsim { ...@@ -92,7 +94,6 @@ struct netdevsim {
bool bpf_xdpoffload_accept; bool bpf_xdpoffload_accept;
bool bpf_map_accept; bool bpf_map_accept;
struct list_head bpf_bound_maps;
#if IS_ENABLED(CONFIG_NET_DEVLINK) #if IS_ENABLED(CONFIG_NET_DEVLINK)
struct devlink *devlink; struct devlink *devlink;
#endif #endif
......
...@@ -314,6 +314,7 @@ class NetdevSim: ...@@ -314,6 +314,7 @@ class NetdevSim:
self.ns = "" self.ns = ""
self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname']) self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname'])
self.sdev_dir = self.dfs_dir + '/sdev/'
self.dfs_refresh() self.dfs_refresh()
def __getitem__(self, key): def __getitem__(self, key):
...@@ -345,12 +346,12 @@ class NetdevSim: ...@@ -345,12 +346,12 @@ class NetdevSim:
return data.strip() return data.strip()
def dfs_num_bound_progs(self): def dfs_num_bound_progs(self):
path = os.path.join(self.dfs_dir, "bpf_bound_progs") path = os.path.join(self.sdev_dir, "bpf_bound_progs")
_, progs = cmd('ls %s' % (path)) _, progs = cmd('ls %s' % (path))
return len(progs.split()) return len(progs.split())
def dfs_get_bound_progs(self, expected): def dfs_get_bound_progs(self, expected):
progs = DebugfsDir(os.path.join(self.dfs_dir, "bpf_bound_progs")) progs = DebugfsDir(os.path.join(self.sdev_dir, "bpf_bound_progs"))
if expected is not None: if expected is not None:
if len(progs) != expected: if len(progs) != expected:
fail(True, "%d BPF programs bound, expected %d" % fail(True, "%d BPF programs bound, expected %d" %
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册