* Re: [PATCH net-next v3 4/7] net: devlink: Add support for port regions
@ 2020-10-04 18:08 kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-10-04 18:08 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 10833 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20201004161257.13945-5-andrew@lunn.ch>
References: <20201004161257.13945-5-andrew@lunn.ch>
TO: Andrew Lunn <andrew@lunn.ch>
Hi Andrew,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Andrew-Lunn/mv88e6xxx-Add-per-port-devlink-regions/20201005-001604
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 456afe01b10085518406022c69cfd2b718d6eaf8
:::::: branch date: 2 hours ago
:::::: commit date: 2 hours ago
config: c6x-randconfig-c003-20201004 (attached as .config)
compiler: c6x-elf-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
echo
echo "coccinelle warnings: (new ones prefixed by >>)"
echo
>> net/core/devlink.c:4649:3-9: preceding lock on line 4629
net/core/devlink.c:4649:3-9: preceding lock on line 4636
vim +4649 net/core/devlink.c
4e54795a27f5610 Alex Vesker 2018-07-12 4611
4e54795a27f5610 Alex Vesker 2018-07-12 4612 static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
4e54795a27f5610 Alex Vesker 2018-07-12 4613 struct netlink_callback *cb)
4e54795a27f5610 Alex Vesker 2018-07-12 4614 {
ee85da535fe30e0 Jiri Pirko 2019-10-05 4615 const struct genl_dumpit_info *info = genl_dumpit_info(cb);
5a46b062e28f57b Jakub Kicinski 2020-05-13 4616 u64 ret_offset, start_offset, end_offset = U64_MAX;
ee85da535fe30e0 Jiri Pirko 2019-10-05 4617 struct nlattr **attrs = info->attrs;
9197384306ff017 Andrew Lunn 2020-10-04 4618 struct devlink_port *port = NULL;
4e54795a27f5610 Alex Vesker 2018-07-12 4619 struct devlink_region *region;
4e54795a27f5610 Alex Vesker 2018-07-12 4620 struct nlattr *chunks_attr;
4e54795a27f5610 Alex Vesker 2018-07-12 4621 const char *region_name;
4e54795a27f5610 Alex Vesker 2018-07-12 4622 struct devlink *devlink;
9197384306ff017 Andrew Lunn 2020-10-04 4623 unsigned int index;
4e54795a27f5610 Alex Vesker 2018-07-12 4624 void *hdr;
4e54795a27f5610 Alex Vesker 2018-07-12 4625 int err;
4e54795a27f5610 Alex Vesker 2018-07-12 4626
4e54795a27f5610 Alex Vesker 2018-07-12 4627 start_offset = *((u64 *)&cb->args[0]);
4e54795a27f5610 Alex Vesker 2018-07-12 4628
dac7c08f988bbc7 Parav Pandit 2019-02-12 @4629 mutex_lock(&devlink_mutex);
4e54795a27f5610 Alex Vesker 2018-07-12 4630 devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
fdd41ec21e15011 Parav Pandit 2019-02-12 4631 if (IS_ERR(devlink)) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4632 err = PTR_ERR(devlink);
dac7c08f988bbc7 Parav Pandit 2019-02-12 4633 goto out_dev;
fdd41ec21e15011 Parav Pandit 2019-02-12 4634 }
4e54795a27f5610 Alex Vesker 2018-07-12 4635
4e54795a27f5610 Alex Vesker 2018-07-12 4636 mutex_lock(&devlink->lock);
4e54795a27f5610 Alex Vesker 2018-07-12 4637
4e54795a27f5610 Alex Vesker 2018-07-12 4638 if (!attrs[DEVLINK_ATTR_REGION_NAME] ||
fdd41ec21e15011 Parav Pandit 2019-02-12 4639 !attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID]) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4640 err = -EINVAL;
4e54795a27f5610 Alex Vesker 2018-07-12 4641 goto out_unlock;
fdd41ec21e15011 Parav Pandit 2019-02-12 4642 }
4e54795a27f5610 Alex Vesker 2018-07-12 4643
9197384306ff017 Andrew Lunn 2020-10-04 4644 if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
9197384306ff017 Andrew Lunn 2020-10-04 4645 index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
9197384306ff017 Andrew Lunn 2020-10-04 4646
9197384306ff017 Andrew Lunn 2020-10-04 4647 port = devlink_port_get_by_index(devlink, index);
9197384306ff017 Andrew Lunn 2020-10-04 4648 if (!port)
9197384306ff017 Andrew Lunn 2020-10-04 @4649 return -ENODEV;
9197384306ff017 Andrew Lunn 2020-10-04 4650 }
9197384306ff017 Andrew Lunn 2020-10-04 4651
4e54795a27f5610 Alex Vesker 2018-07-12 4652 region_name = nla_data(attrs[DEVLINK_ATTR_REGION_NAME]);
9197384306ff017 Andrew Lunn 2020-10-04 4653
9197384306ff017 Andrew Lunn 2020-10-04 4654 if (port)
9197384306ff017 Andrew Lunn 2020-10-04 4655 region = devlink_port_region_get_by_name(port, region_name);
9197384306ff017 Andrew Lunn 2020-10-04 4656 else
4e54795a27f5610 Alex Vesker 2018-07-12 4657 region = devlink_region_get_by_name(devlink, region_name);
9197384306ff017 Andrew Lunn 2020-10-04 4658
fdd41ec21e15011 Parav Pandit 2019-02-12 4659 if (!region) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4660 err = -EINVAL;
4e54795a27f5610 Alex Vesker 2018-07-12 4661 goto out_unlock;
fdd41ec21e15011 Parav Pandit 2019-02-12 4662 }
4e54795a27f5610 Alex Vesker 2018-07-12 4663
5a46b062e28f57b Jakub Kicinski 2020-05-13 4664 if (attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR] &&
5a46b062e28f57b Jakub Kicinski 2020-05-13 4665 attrs[DEVLINK_ATTR_REGION_CHUNK_LEN]) {
5a46b062e28f57b Jakub Kicinski 2020-05-13 4666 if (!start_offset)
5a46b062e28f57b Jakub Kicinski 2020-05-13 4667 start_offset =
5a46b062e28f57b Jakub Kicinski 2020-05-13 4668 nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR]);
5a46b062e28f57b Jakub Kicinski 2020-05-13 4669
5a46b062e28f57b Jakub Kicinski 2020-05-13 4670 end_offset = nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR]);
5a46b062e28f57b Jakub Kicinski 2020-05-13 4671 end_offset += nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_LEN]);
5a46b062e28f57b Jakub Kicinski 2020-05-13 4672 }
5a46b062e28f57b Jakub Kicinski 2020-05-13 4673
5a46b062e28f57b Jakub Kicinski 2020-05-13 4674 if (end_offset > region->size)
5a46b062e28f57b Jakub Kicinski 2020-05-13 4675 end_offset = region->size;
5a46b062e28f57b Jakub Kicinski 2020-05-13 4676
d5b90e99e1d51b7 Jacob Keller 2020-02-04 4677 /* return 0 if there is no further data to read */
5a46b062e28f57b Jakub Kicinski 2020-05-13 4678 if (start_offset == end_offset) {
d5b90e99e1d51b7 Jacob Keller 2020-02-04 4679 err = 0;
d5b90e99e1d51b7 Jacob Keller 2020-02-04 4680 goto out_unlock;
d5b90e99e1d51b7 Jacob Keller 2020-02-04 4681 }
d5b90e99e1d51b7 Jacob Keller 2020-02-04 4682
4e54795a27f5610 Alex Vesker 2018-07-12 4683 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
4e54795a27f5610 Alex Vesker 2018-07-12 4684 &devlink_nl_family, NLM_F_ACK | NLM_F_MULTI,
4e54795a27f5610 Alex Vesker 2018-07-12 4685 DEVLINK_CMD_REGION_READ);
fdd41ec21e15011 Parav Pandit 2019-02-12 4686 if (!hdr) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4687 err = -EMSGSIZE;
4e54795a27f5610 Alex Vesker 2018-07-12 4688 goto out_unlock;
fdd41ec21e15011 Parav Pandit 2019-02-12 4689 }
4e54795a27f5610 Alex Vesker 2018-07-12 4690
4e54795a27f5610 Alex Vesker 2018-07-12 4691 err = devlink_nl_put_handle(skb, devlink);
4e54795a27f5610 Alex Vesker 2018-07-12 4692 if (err)
4e54795a27f5610 Alex Vesker 2018-07-12 4693 goto nla_put_failure;
4e54795a27f5610 Alex Vesker 2018-07-12 4694
9197384306ff017 Andrew Lunn 2020-10-04 4695 if (region->port)
9197384306ff017 Andrew Lunn 2020-10-04 4696 if (nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX,
9197384306ff017 Andrew Lunn 2020-10-04 4697 region->port->index))
9197384306ff017 Andrew Lunn 2020-10-04 4698 goto nla_put_failure;
9197384306ff017 Andrew Lunn 2020-10-04 4699
4e54795a27f5610 Alex Vesker 2018-07-12 4700 err = nla_put_string(skb, DEVLINK_ATTR_REGION_NAME, region_name);
4e54795a27f5610 Alex Vesker 2018-07-12 4701 if (err)
4e54795a27f5610 Alex Vesker 2018-07-12 4702 goto nla_put_failure;
4e54795a27f5610 Alex Vesker 2018-07-12 4703
ae0be8de9a53cda Michal Kubecek 2019-04-26 4704 chunks_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_REGION_CHUNKS);
fdd41ec21e15011 Parav Pandit 2019-02-12 4705 if (!chunks_attr) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4706 err = -EMSGSIZE;
4e54795a27f5610 Alex Vesker 2018-07-12 4707 goto nla_put_failure;
fdd41ec21e15011 Parav Pandit 2019-02-12 4708 }
4e54795a27f5610 Alex Vesker 2018-07-12 4709
4e54795a27f5610 Alex Vesker 2018-07-12 4710 err = devlink_nl_region_read_snapshot_fill(skb, devlink,
4e54795a27f5610 Alex Vesker 2018-07-12 4711 region, attrs,
4e54795a27f5610 Alex Vesker 2018-07-12 4712 start_offset,
5a46b062e28f57b Jakub Kicinski 2020-05-13 4713 end_offset, &ret_offset);
4e54795a27f5610 Alex Vesker 2018-07-12 4714
4e54795a27f5610 Alex Vesker 2018-07-12 4715 if (err && err != -EMSGSIZE)
4e54795a27f5610 Alex Vesker 2018-07-12 4716 goto nla_put_failure;
4e54795a27f5610 Alex Vesker 2018-07-12 4717
4e54795a27f5610 Alex Vesker 2018-07-12 4718 /* Check if there was any progress done to prevent infinite loop */
fdd41ec21e15011 Parav Pandit 2019-02-12 4719 if (ret_offset == start_offset) {
fdd41ec21e15011 Parav Pandit 2019-02-12 4720 err = -EINVAL;
4e54795a27f5610 Alex Vesker 2018-07-12 4721 goto nla_put_failure;
fdd41ec21e15011 Parav Pandit 2019-02-12 4722 }
4e54795a27f5610 Alex Vesker 2018-07-12 4723
4e54795a27f5610 Alex Vesker 2018-07-12 4724 *((u64 *)&cb->args[0]) = ret_offset;
4e54795a27f5610 Alex Vesker 2018-07-12 4725
4e54795a27f5610 Alex Vesker 2018-07-12 4726 nla_nest_end(skb, chunks_attr);
4e54795a27f5610 Alex Vesker 2018-07-12 4727 genlmsg_end(skb, hdr);
4e54795a27f5610 Alex Vesker 2018-07-12 4728 mutex_unlock(&devlink->lock);
4e54795a27f5610 Alex Vesker 2018-07-12 4729 mutex_unlock(&devlink_mutex);
4e54795a27f5610 Alex Vesker 2018-07-12 4730
4e54795a27f5610 Alex Vesker 2018-07-12 4731 return skb->len;
4e54795a27f5610 Alex Vesker 2018-07-12 4732
4e54795a27f5610 Alex Vesker 2018-07-12 4733 nla_put_failure:
4e54795a27f5610 Alex Vesker 2018-07-12 4734 genlmsg_cancel(skb, hdr);
4e54795a27f5610 Alex Vesker 2018-07-12 4735 out_unlock:
4e54795a27f5610 Alex Vesker 2018-07-12 4736 mutex_unlock(&devlink->lock);
dac7c08f988bbc7 Parav Pandit 2019-02-12 4737 out_dev:
4e54795a27f5610 Alex Vesker 2018-07-12 4738 mutex_unlock(&devlink_mutex);
fdd41ec21e15011 Parav Pandit 2019-02-12 4739 return err;
4e54795a27f5610 Alex Vesker 2018-07-12 4740 }
4e54795a27f5610 Alex Vesker 2018-07-12 4741
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 21992 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH net-next v3 4/7] net: devlink: Add support for port regions
2020-10-04 16:12 [PATCH net-next v3 0/7] mv88e6xxx: Add per port devlink regions Andrew Lunn
@ 2020-10-04 16:12 ` Andrew Lunn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2020-10-04 16:12 UTC (permalink / raw)
To: David Miller
Cc: netdev, Florian Fainelli, Vladimir Oltean, Jiri Pirko,
Jakub Kicinski, Andrew Lunn, Vladimir Oltean
Allow regions to be registered to a devlink port. The same netlink API
is used, but the port index is provided to indicate when a region is a
port region as opposed to a device region.
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Tested-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
include/net/devlink.h | 27 +++++
net/core/devlink.c | 250 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 251 insertions(+), 26 deletions(-)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 89ede1ce3a3a..237ba5e29a3b 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -110,6 +110,7 @@ struct devlink_port_attrs {
struct devlink_port {
struct list_head list;
struct list_head param_list;
+ struct list_head region_list;
struct devlink *devlink;
unsigned int index;
bool registered;
@@ -591,6 +592,26 @@ struct devlink_region_ops {
void *priv;
};
+/**
+ * struct devlink_port_region_ops - Region operations for a port
+ * @name: region name
+ * @destructor: callback used to free snapshot memory when deleting
+ * @snapshot: callback to request an immediate snapshot. On success,
+ * the data variable must be updated to point to the snapshot data.
+ * The function will be called while the devlink instance lock is
+ * held.
+ * @priv: Pointer to driver private data for the region operation
+ */
+struct devlink_port_region_ops {
+ const char *name;
+ void (*destructor)(const void *data);
+ int (*snapshot)(struct devlink_port *port,
+ const struct devlink_port_region_ops *ops,
+ struct netlink_ext_ack *extack,
+ u8 **data);
+ void *priv;
+};
+
struct devlink_fmsg;
struct devlink_health_reporter;
@@ -1445,7 +1466,13 @@ struct devlink_region *
devlink_region_create(struct devlink *devlink,
const struct devlink_region_ops *ops,
u32 region_max_snapshots, u64 region_size);
+struct devlink_region *
+devlink_port_region_create(struct devlink_port *port,
+ const struct devlink_port_region_ops *ops,
+ u32 region_max_snapshots, u64 region_size);
void devlink_region_destroy(struct devlink_region *region);
+void devlink_port_region_destroy(struct devlink_region *region);
+
int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
int devlink_region_snapshot_create(struct devlink_region *region,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 20224fd1ebaf..65b8ac8b5fba 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -347,8 +347,12 @@ devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb,
struct devlink_region {
struct devlink *devlink;
+ struct devlink_port *port;
struct list_head list;
- const struct devlink_region_ops *ops;
+ union {
+ const struct devlink_region_ops *ops;
+ const struct devlink_port_region_ops *port_ops;
+ };
struct list_head snapshot_list;
u32 max_snapshots;
u32 cur_snapshots;
@@ -374,6 +378,19 @@ devlink_region_get_by_name(struct devlink *devlink, const char *region_name)
return NULL;
}
+static struct devlink_region *
+devlink_port_region_get_by_name(struct devlink_port *port,
+ const char *region_name)
+{
+ struct devlink_region *region;
+
+ list_for_each_entry(region, &port->region_list, list)
+ if (!strcmp(region->ops->name, region_name))
+ return region;
+
+ return NULL;
+}
+
static struct devlink_snapshot *
devlink_region_snapshot_get_by_id(struct devlink_region *region, u32 id)
{
@@ -3926,6 +3943,11 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
if (err)
goto nla_put_failure;
+ if (region->port)
+ if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
+ region->port->index))
+ goto nla_put_failure;
+
err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME, region->ops->name);
if (err)
goto nla_put_failure;
@@ -3973,6 +3995,11 @@ devlink_nl_region_notify_build(struct devlink_region *region,
if (err)
goto out_cancel_msg;
+ if (region->port)
+ if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
+ region->port->index))
+ goto out_cancel_msg;
+
err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME,
region->ops->name);
if (err)
@@ -4219,16 +4246,30 @@ static int devlink_nl_cmd_region_get_doit(struct sk_buff *skb,
struct genl_info *info)
{
struct devlink *devlink = info->user_ptr[0];
+ struct devlink_port *port = NULL;
struct devlink_region *region;
const char *region_name;
struct sk_buff *msg;
+ unsigned int index;
int err;
if (!info->attrs[DEVLINK_ATTR_REGION_NAME])
return -EINVAL;
+ if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
+ index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
+
+ port = devlink_port_get_by_index(devlink, index);
+ if (!port)
+ return -ENODEV;
+ }
+
region_name = nla_data(info->attrs[DEVLINK_ATTR_REGION_NAME]);
- region = devlink_region_get_by_name(devlink, region_name);
+ if (port)
+ region = devlink_port_region_get_by_name(port, region_name);
+ else
+ region = devlink_region_get_by_name(devlink, region_name);
+
if (!region)
return -EINVAL;
@@ -4247,10 +4288,75 @@ static int devlink_nl_cmd_region_get_doit(struct sk_buff *skb,
return genlmsg_reply(msg, info);
}
+static int devlink_nl_cmd_region_get_port_dumpit(struct sk_buff *msg,
+ struct netlink_callback *cb,
+ struct devlink_port *port,
+ int *idx,
+ int start)
+{
+ struct devlink_region *region;
+ int err = 0;
+
+ list_for_each_entry(region, &port->region_list, list) {
+ if (*idx < start) {
+ (*idx)++;
+ continue;
+ }
+ err = devlink_nl_region_fill(msg, port->devlink,
+ DEVLINK_CMD_REGION_GET,
+ NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq,
+ NLM_F_MULTI, region);
+ if (err)
+ goto out;
+ (*idx)++;
+ }
+
+out:
+ return err;
+}
+
+static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg,
+ struct netlink_callback *cb,
+ struct devlink *devlink,
+ int *idx,
+ int start)
+{
+ struct devlink_region *region;
+ struct devlink_port *port;
+ int err = 0;
+
+ mutex_lock(&devlink->lock);
+ list_for_each_entry(region, &devlink->region_list, list) {
+ if (*idx < start) {
+ (*idx)++;
+ continue;
+ }
+ err = devlink_nl_region_fill(msg, devlink,
+ DEVLINK_CMD_REGION_GET,
+ NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq,
+ NLM_F_MULTI, region);
+ if (err)
+ goto out;
+ (*idx)++;
+ }
+
+ list_for_each_entry(port, &devlink->port_list, list) {
+ err = devlink_nl_cmd_region_get_port_dumpit(msg, cb, port, idx,
+ start);
+ if (err)
+ goto out;
+ }
+
+out:
+ mutex_unlock(&devlink->lock);
+ return err;
+}
+
static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg,
struct netlink_callback *cb)
{
- struct devlink_region *region;
struct devlink *devlink;
int start = cb->args[0];
int idx = 0;
@@ -4260,25 +4366,10 @@ static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg,
list_for_each_entry(devlink, &devlink_list, list) {
if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
continue;
-
- mutex_lock(&devlink->lock);
- list_for_each_entry(region, &devlink->region_list, list) {
- if (idx < start) {
- idx++;
- continue;
- }
- err = devlink_nl_region_fill(msg, devlink,
- DEVLINK_CMD_REGION_GET,
- NETLINK_CB(cb->skb).portid,
- cb->nlh->nlmsg_seq,
- NLM_F_MULTI, region);
- if (err) {
- mutex_unlock(&devlink->lock);
- goto out;
- }
- idx++;
- }
- mutex_unlock(&devlink->lock);
+ err = devlink_nl_cmd_region_get_devlink_dumpit(msg, cb, devlink,
+ &idx, start);
+ if (err)
+ goto out;
}
out:
mutex_unlock(&devlink_mutex);
@@ -4291,8 +4382,10 @@ static int devlink_nl_cmd_region_del(struct sk_buff *skb,
{
struct devlink *devlink = info->user_ptr[0];
struct devlink_snapshot *snapshot;
+ struct devlink_port *port = NULL;
struct devlink_region *region;
const char *region_name;
+ unsigned int index;
u32 snapshot_id;
if (!info->attrs[DEVLINK_ATTR_REGION_NAME] ||
@@ -4302,7 +4395,19 @@ static int devlink_nl_cmd_region_del(struct sk_buff *skb,
region_name = nla_data(info->attrs[DEVLINK_ATTR_REGION_NAME]);
snapshot_id = nla_get_u32(info->attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
- region = devlink_region_get_by_name(devlink, region_name);
+ if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
+ index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
+
+ port = devlink_port_get_by_index(devlink, index);
+ if (!port)
+ return -ENODEV;
+ }
+
+ if (port)
+ region = devlink_port_region_get_by_name(port, region_name);
+ else
+ region = devlink_region_get_by_name(devlink, region_name);
+
if (!region)
return -EINVAL;
@@ -4319,9 +4424,11 @@ devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info)
{
struct devlink *devlink = info->user_ptr[0];
struct devlink_snapshot *snapshot;
+ struct devlink_port *port = NULL;
struct nlattr *snapshot_id_attr;
struct devlink_region *region;
const char *region_name;
+ unsigned int index;
u32 snapshot_id;
u8 *data;
int err;
@@ -4332,7 +4439,20 @@ devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info)
}
region_name = nla_data(info->attrs[DEVLINK_ATTR_REGION_NAME]);
- region = devlink_region_get_by_name(devlink, region_name);
+
+ if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
+ index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
+
+ port = devlink_port_get_by_index(devlink, index);
+ if (!port)
+ return -ENODEV;
+ }
+
+ if (port)
+ region = devlink_port_region_get_by_name(port, region_name);
+ else
+ region = devlink_region_get_by_name(devlink, region_name);
+
if (!region) {
NL_SET_ERR_MSG_MOD(info->extack, "The requested region does not exist");
return -EINVAL;
@@ -4368,7 +4488,12 @@ devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info)
}
}
- err = region->ops->snapshot(devlink, region->ops, info->extack, &data);
+ if (port)
+ err = region->port_ops->snapshot(port, region->port_ops,
+ info->extack, &data);
+ else
+ err = region->ops->snapshot(devlink, region->ops,
+ info->extack, &data);
if (err)
goto err_snapshot_capture;
@@ -4490,10 +4615,12 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
u64 ret_offset, start_offset, end_offset = U64_MAX;
struct nlattr **attrs = info->attrs;
+ struct devlink_port *port = NULL;
struct devlink_region *region;
struct nlattr *chunks_attr;
const char *region_name;
struct devlink *devlink;
+ unsigned int index;
void *hdr;
int err;
@@ -4514,8 +4641,21 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
goto out_unlock;
}
+ if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
+ index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
+
+ port = devlink_port_get_by_index(devlink, index);
+ if (!port)
+ return -ENODEV;
+ }
+
region_name = nla_data(attrs[DEVLINK_ATTR_REGION_NAME]);
- region = devlink_region_get_by_name(devlink, region_name);
+
+ if (port)
+ region = devlink_port_region_get_by_name(port, region_name);
+ else
+ region = devlink_region_get_by_name(devlink, region_name);
+
if (!region) {
err = -EINVAL;
goto out_unlock;
@@ -4552,6 +4692,11 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
if (err)
goto nla_put_failure;
+ if (region->port)
+ if (nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX,
+ region->port->index))
+ goto nla_put_failure;
+
err = nla_put_string(skb, DEVLINK_ATTR_REGION_NAME, region_name);
if (err)
goto nla_put_failure;
@@ -7666,6 +7811,7 @@ int devlink_port_register(struct devlink *devlink,
mutex_init(&devlink_port->reporters_lock);
list_add_tail(&devlink_port->list, &devlink->port_list);
INIT_LIST_HEAD(&devlink_port->param_list);
+ INIT_LIST_HEAD(&devlink_port->region_list);
mutex_unlock(&devlink->lock);
INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn);
devlink_port_type_warn_schedule(devlink_port);
@@ -7689,6 +7835,7 @@ void devlink_port_unregister(struct devlink_port *devlink_port)
list_del(&devlink_port->list);
mutex_unlock(&devlink->lock);
WARN_ON(!list_empty(&devlink_port->reporter_list));
+ WARN_ON(!list_empty(&devlink_port->region_list));
mutex_destroy(&devlink_port->reporters_lock);
}
EXPORT_SYMBOL_GPL(devlink_port_unregister);
@@ -8768,6 +8915,57 @@ devlink_region_create(struct devlink *devlink,
}
EXPORT_SYMBOL_GPL(devlink_region_create);
+/**
+ * devlink_port_region_create - create a new address region for a port
+ *
+ * @port: devlink port
+ * @ops: region operations and name
+ * @region_max_snapshots: Maximum supported number of snapshots for region
+ * @region_size: size of region
+ */
+struct devlink_region *
+devlink_port_region_create(struct devlink_port *port,
+ const struct devlink_port_region_ops *ops,
+ u32 region_max_snapshots, u64 region_size)
+{
+ struct devlink *devlink = port->devlink;
+ struct devlink_region *region;
+ int err = 0;
+
+ if (WARN_ON(!ops) || WARN_ON(!ops->destructor))
+ return ERR_PTR(-EINVAL);
+
+ mutex_lock(&devlink->lock);
+
+ if (devlink_port_region_get_by_name(port, ops->name)) {
+ err = -EEXIST;
+ goto unlock;
+ }
+
+ region = kzalloc(sizeof(*region), GFP_KERNEL);
+ if (!region) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ region->devlink = devlink;
+ region->port = port;
+ region->max_snapshots = region_max_snapshots;
+ region->port_ops = ops;
+ region->size = region_size;
+ INIT_LIST_HEAD(®ion->snapshot_list);
+ list_add_tail(®ion->list, &port->region_list);
+ devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW);
+
+ mutex_unlock(&devlink->lock);
+ return region;
+
+unlock:
+ mutex_unlock(&devlink->lock);
+ return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(devlink_port_region_create);
+
/**
* devlink_region_destroy - destroy address region
*
--
2.28.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-04 18:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-04 18:08 [PATCH net-next v3 4/7] net: devlink: Add support for port regions kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2020-10-04 16:12 [PATCH net-next v3 0/7] mv88e6xxx: Add per port devlink regions Andrew Lunn
2020-10-04 16:12 ` [PATCH net-next v3 4/7] net: devlink: Add support for port regions Andrew Lunn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.