From patchwork Tue Sep 19 22:27:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391977 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BC183B7BA for ; Tue, 19 Sep 2023 22:15:37 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CDCF9 for ; Tue, 19 Sep 2023 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161732; x=1726697732; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DF+OgjOupW4yRX2XBuIjTF3HBVeVWPBrqe0UHutLPZM=; b=VvADazzLCedeeUtdbabrgeQgcm1FEQEKFh8hDewkoQxE8HRJGR/nuojR ODlie2GD/p5jZC5+B+eWvjk8iKIHAOSQANVy0mUIN1X3V2WWY0BZ02gme DQn7Cw04SnbJ4FQVafBKZdzkqSQ3X0TrokhI/xkNYmh3sncDbHTlFmbl+ 2HdLqK8o87lJuyJNPFmmtjfo4Y4fnKGRxrjNU8LtT/a50v5mX2oFKS0AJ AZZW4j7Zv9k2zrMnYKQAauD+RoUu6LoLyCIWa+1vB4OUIAGHy5NV8BE/Y E1YrUtkrravVCPnmRBb1p00pmthUFx9P1mlgb4YwC/ClCCRa0DaEnlqEu w==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="370378419" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="370378419" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:11:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="749644522" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="749644522" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga007.fm.intel.com with ESMTP; 19 Sep 2023 15:11:51 -0700 Subject: [net-next PATCH v3 01/10] netdev-genl: spec: Extend netdev netlink spec in YAML for queue From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:20 -0700 Message-ID: <169516244040.7377.16515332696427625794.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for queue information. Add code generated from the spec. Note: The "q-type" attribute currently takes values 0 and 1 for rx and tx queue type respectively. I haven't figured out the ynl library changes to support string user input ("rx" and "tx") to enum value conversion in the generated file. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- Documentation/netlink/specs/netdev.yaml | 52 ++++++++++ include/uapi/linux/netdev.h | 17 +++ net/core/netdev-genl-gen.c | 26 +++++ net/core/netdev-genl-gen.h | 3 + net/core/netdev-genl.c | 10 ++ tools/include/uapi/linux/netdev.h | 17 +++ tools/net/ynl/generated/netdev-user.c | 159 +++++++++++++++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 101 ++++++++++++++++++++ 8 files changed, 385 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index c46fcc78fc04..7b5d4cdff48b 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -55,6 +55,10 @@ definitions: name: hash doc: Device is capable of exposing receive packet hash via bpf_xdp_metadata_rx_hash(). + - + name: queue-type + type: enum + entries: [ rx, tx ] attribute-sets: - @@ -89,6 +93,32 @@ attribute-sets: enum: xdp-rx-metadata enum-as-flags: true + - + name: queue + attributes: + - + name: q-id + doc: queue index + type: u32 + - + name: ifindex + doc: netdev ifindex + type: u32 + checks: + min: 1 + - + name: q-type + doc: queue type as rx, tx + type: u32 + enum: queue-type + - + name: napi-id + doc: napi id + type: u32 + - + name: tx-maxrate + type: u32 + operations: list: - @@ -122,6 +152,28 @@ operations: doc: Notification about device configuration being changed. notify: dev-get mcgrp: mgmt + - + name: queue-get + doc: queue information + attribute-set: queue + do: + request: + attributes: + - ifindex + - q-type + - q-id + reply: &queue-get-op + attributes: + - q-id + - q-type + - napi-id + - ifindex + - tx-maxrate + dump: + request: + attributes: + - ifindex + reply: *queue-get-op mcast-groups: list: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 2943a151d4f1..bb3713231b0b 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -53,6 +53,11 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +enum netdev_queue_type { + NETDEV_QUEUE_TYPE_RX, + NETDEV_QUEUE_TYPE_TX, +}; + enum { NETDEV_A_DEV_IFINDEX = 1, NETDEV_A_DEV_PAD, @@ -64,11 +69,23 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_QUEUE_Q_ID = 1, + NETDEV_A_QUEUE_IFINDEX, + NETDEV_A_QUEUE_Q_TYPE, + NETDEV_A_QUEUE_NAPI_ID, + NETDEV_A_QUEUE_TX_MAXRATE, + + __NETDEV_A_QUEUE_MAX, + NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_QUEUE_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c index ea9231378aa6..e3632ed597b4 100644 --- a/net/core/netdev-genl-gen.c +++ b/net/core/netdev-genl-gen.c @@ -15,6 +15,18 @@ static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX + 1 [NETDEV_A_DEV_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), }; +/* NETDEV_CMD_QUEUE_GET - do */ +static const struct nla_policy netdev_queue_get_do_nl_policy[NETDEV_A_QUEUE_Q_TYPE + 1] = { + [NETDEV_A_QUEUE_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), + [NETDEV_A_QUEUE_Q_TYPE] = NLA_POLICY_MAX(NLA_U32, 1), + [NETDEV_A_QUEUE_Q_ID] = { .type = NLA_U32, }, +}; + +/* NETDEV_CMD_QUEUE_GET - dump */ +static const struct nla_policy netdev_queue_get_dump_nl_policy[NETDEV_A_QUEUE_IFINDEX + 1] = { + [NETDEV_A_QUEUE_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { { @@ -29,6 +41,20 @@ static const struct genl_split_ops netdev_nl_ops[] = { .dumpit = netdev_nl_dev_get_dumpit, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NETDEV_CMD_QUEUE_GET, + .doit = netdev_nl_queue_get_doit, + .policy = netdev_queue_get_do_nl_policy, + .maxattr = NETDEV_A_QUEUE_Q_TYPE, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_QUEUE_GET, + .dumpit = netdev_nl_queue_get_dumpit, + .policy = netdev_queue_get_dump_nl_policy, + .maxattr = NETDEV_A_QUEUE_IFINDEX, + .flags = GENL_CMD_CAP_DUMP, + }, }; static const struct genl_multicast_group netdev_nl_mcgrps[] = { diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h index 7b370c073e7d..263c94f77bad 100644 --- a/net/core/netdev-genl-gen.h +++ b/net/core/netdev-genl-gen.h @@ -13,6 +13,9 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info); +int netdev_nl_queue_get_dumpit(struct sk_buff *skb, + struct netlink_callback *cb); enum { NETDEV_NLGRP_MGMT, diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index fe61f85bcf33..336c608e6a6b 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -129,6 +129,16 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + return -EOPNOTSUPP; +} + static int netdev_genl_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 2943a151d4f1..bb3713231b0b 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -53,6 +53,11 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +enum netdev_queue_type { + NETDEV_QUEUE_TYPE_RX, + NETDEV_QUEUE_TYPE_TX, +}; + enum { NETDEV_A_DEV_IFINDEX = 1, NETDEV_A_DEV_PAD, @@ -64,11 +69,23 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_QUEUE_Q_ID = 1, + NETDEV_A_QUEUE_IFINDEX, + NETDEV_A_QUEUE_Q_TYPE, + NETDEV_A_QUEUE_NAPI_ID, + NETDEV_A_QUEUE_TX_MAXRATE, + + __NETDEV_A_QUEUE_MAX, + NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_QUEUE_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index b5ffe8cd1144..749b4bea3c6c 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -18,6 +18,7 @@ static const char * const netdev_op_strmap[] = { [NETDEV_CMD_DEV_ADD_NTF] = "dev-add-ntf", [NETDEV_CMD_DEV_DEL_NTF] = "dev-del-ntf", [NETDEV_CMD_DEV_CHANGE_NTF] = "dev-change-ntf", + [NETDEV_CMD_QUEUE_GET] = "queue-get", }; const char *netdev_op_str(int op) @@ -58,6 +59,18 @@ const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value) return netdev_xdp_rx_metadata_strmap[value]; } +static const char * const netdev_queue_type_strmap[] = { + [0] = "rx", + [1] = "tx", +}; + +const char *netdev_queue_type_str(enum netdev_queue_type value) +{ + if (value < 0 || value >= (int)MNL_ARRAY_SIZE(netdev_queue_type_strmap)) + return NULL; + return netdev_queue_type_strmap[value]; +} + /* Policies */ struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { [NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, @@ -72,6 +85,19 @@ struct ynl_policy_nest netdev_dev_nest = { .table = netdev_dev_policy, }; +struct ynl_policy_attr netdev_queue_policy[NETDEV_A_QUEUE_MAX + 1] = { + [NETDEV_A_QUEUE_Q_ID] = { .name = "q-id", .type = YNL_PT_U32, }, + [NETDEV_A_QUEUE_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NETDEV_A_QUEUE_Q_TYPE] = { .name = "q-type", .type = YNL_PT_U32, }, + [NETDEV_A_QUEUE_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, + [NETDEV_A_QUEUE_TX_MAXRATE] = { .name = "tx-maxrate", .type = YNL_PT_U32, }, +}; + +struct ynl_policy_nest netdev_queue_nest = { + .max_attr = NETDEV_A_QUEUE_MAX, + .table = netdev_queue_policy, +}; + /* Common nested types */ /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ @@ -197,6 +223,139 @@ void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp) free(rsp); } +/* ============== NETDEV_CMD_QUEUE_GET ============== */ +/* NETDEV_CMD_QUEUE_GET - do */ +void netdev_queue_get_req_free(struct netdev_queue_get_req *req) +{ + free(req); +} + +void netdev_queue_get_rsp_free(struct netdev_queue_get_rsp *rsp) +{ + free(rsp); +} + +int netdev_queue_get_rsp_parse(const struct nlmsghdr *nlh, void *data) +{ + struct ynl_parse_arg *yarg = data; + struct netdev_queue_get_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + unsigned int type = mnl_attr_get_type(attr); + + if (type == NETDEV_A_QUEUE_Q_ID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.q_id = 1; + dst->q_id = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_QUEUE_Q_TYPE) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.q_type = 1; + dst->q_type = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_QUEUE_NAPI_ID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.napi_id = 1; + dst->napi_id = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_QUEUE_IFINDEX) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.ifindex = 1; + dst->ifindex = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_QUEUE_TX_MAXRATE) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.tx_maxrate = 1; + dst->tx_maxrate = mnl_attr_get_u32(attr); + } + } + + return MNL_CB_OK; +} + +struct netdev_queue_get_rsp * +netdev_queue_get(struct ynl_sock *ys, struct netdev_queue_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct netdev_queue_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NETDEV_CMD_QUEUE_GET, 1); + ys->req_policy = &netdev_queue_nest; + yrs.yarg.rsp_policy = &netdev_queue_nest; + + if (req->_present.ifindex) + mnl_attr_put_u32(nlh, NETDEV_A_QUEUE_IFINDEX, req->ifindex); + if (req->_present.q_type) + mnl_attr_put_u32(nlh, NETDEV_A_QUEUE_Q_TYPE, req->q_type); + if (req->_present.q_id) + mnl_attr_put_u32(nlh, NETDEV_A_QUEUE_Q_ID, req->q_id); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = netdev_queue_get_rsp_parse; + yrs.rsp_cmd = NETDEV_CMD_QUEUE_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + netdev_queue_get_rsp_free(rsp); + return NULL; +} + +/* NETDEV_CMD_QUEUE_GET - dump */ +void netdev_queue_get_list_free(struct netdev_queue_get_list *rsp) +{ + struct netdev_queue_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + free(rsp); + } +} + +struct netdev_queue_get_list * +netdev_queue_get_dump(struct ynl_sock *ys, + struct netdev_queue_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.ys = ys; + yds.alloc_sz = sizeof(struct netdev_queue_get_list); + yds.cb = netdev_queue_get_rsp_parse; + yds.rsp_cmd = NETDEV_CMD_QUEUE_GET; + yds.rsp_policy = &netdev_queue_nest; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NETDEV_CMD_QUEUE_GET, 1); + ys->req_policy = &netdev_queue_nest; + + if (req->_present.ifindex) + mnl_attr_put_u32(nlh, NETDEV_A_QUEUE_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + netdev_queue_get_list_free(yds.first); + return NULL; +} + static const struct ynl_ntf_info netdev_ntf_info[] = { [NETDEV_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct netdev_dev_get_ntf), diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index b4351ff34595..cc938c6ba492 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -19,6 +19,7 @@ extern const struct ynl_family ynl_netdev_family; const char *netdev_op_str(int op); const char *netdev_xdp_act_str(enum netdev_xdp_act value); const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value); +const char *netdev_queue_type_str(enum netdev_queue_type value); /* Common nested types */ /* ============== NETDEV_CMD_DEV_GET ============== */ @@ -87,4 +88,104 @@ struct netdev_dev_get_ntf { void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp); +/* ============== NETDEV_CMD_QUEUE_GET ============== */ +/* NETDEV_CMD_QUEUE_GET - do */ +struct netdev_queue_get_req { + struct { + __u32 ifindex:1; + __u32 q_type:1; + __u32 q_id:1; + } _present; + + __u32 ifindex; + enum netdev_queue_type q_type; + __u32 q_id; +}; + +static inline struct netdev_queue_get_req *netdev_queue_get_req_alloc(void) +{ + return calloc(1, sizeof(struct netdev_queue_get_req)); +} +void netdev_queue_get_req_free(struct netdev_queue_get_req *req); + +static inline void +netdev_queue_get_req_set_ifindex(struct netdev_queue_get_req *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +netdev_queue_get_req_set_q_type(struct netdev_queue_get_req *req, + enum netdev_queue_type q_type) +{ + req->_present.q_type = 1; + req->q_type = q_type; +} +static inline void +netdev_queue_get_req_set_q_id(struct netdev_queue_get_req *req, __u32 q_id) +{ + req->_present.q_id = 1; + req->q_id = q_id; +} + +struct netdev_queue_get_rsp { + struct { + __u32 q_id:1; + __u32 q_type:1; + __u32 napi_id:1; + __u32 ifindex:1; + __u32 tx_maxrate:1; + } _present; + + __u32 q_id; + enum netdev_queue_type q_type; + __u32 napi_id; + __u32 ifindex; + __u32 tx_maxrate; +}; + +void netdev_queue_get_rsp_free(struct netdev_queue_get_rsp *rsp); + +/* + * queue information + */ +struct netdev_queue_get_rsp * +netdev_queue_get(struct ynl_sock *ys, struct netdev_queue_get_req *req); + +/* NETDEV_CMD_QUEUE_GET - dump */ +struct netdev_queue_get_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct netdev_queue_get_req_dump * +netdev_queue_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct netdev_queue_get_req_dump)); +} +void netdev_queue_get_req_dump_free(struct netdev_queue_get_req_dump *req); + +static inline void +netdev_queue_get_req_dump_set_ifindex(struct netdev_queue_get_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct netdev_queue_get_list { + struct netdev_queue_get_list *next; + struct netdev_queue_get_rsp obj __attribute__ ((aligned (8))); +}; + +void netdev_queue_get_list_free(struct netdev_queue_get_list *rsp); + +struct netdev_queue_get_list * +netdev_queue_get_dump(struct ynl_sock *ys, + struct netdev_queue_get_req_dump *req); + #endif /* _LINUX_NETDEV_GEN_H */ From patchwork Tue Sep 19 22:27:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391973 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E256E3B291 for ; Tue, 19 Sep 2023 22:15:34 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAD4C0 for ; Tue, 19 Sep 2023 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161732; x=1726697732; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WhHfZAjvfhDGHypHoZliu8btlXYu7HXtD48tDwbRmt8=; b=hHkbzRIAATdP1DldouVxh+Q+CyR/V8IVJHCxQznYmuy9chpdnwKj7zlq LiWHW7/udINpHlB871M82lY1VGWCBeBu8ftpVRSzeH4jo5f4fwF5KRGVZ mw5J1JTZkstZdn1mC04RaMjHV2M6dRlyk+d5kQMafk6827fySkaeSllKU bI5O9gkr+oEeOz7R3eC/4DPi+o1GRUnwpyTwFCl6vpBrgkp9a95VMD7Fl SZMdTo/g0HNJEfVWTuyV0hXI2ngXEPxSRyi3Cd/AWeX0bBCgxThz3S6Ng iXjQwVZVDKI+j39LwdDn6YziUEhHLwlVuXmm7xYOrEEfuYLLBSEUbk4E1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="382813030" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="382813030" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:11:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="1077162435" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="1077162435" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga005.fm.intel.com with ESMTP; 19 Sep 2023 15:11:57 -0700 Subject: [net-next PATCH v3 02/10] net: Add queue and napi association From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:25 -0700 Message-ID: <169516244584.7377.16939532936643936800.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add the napi pointer in netdev queue for tracking the napi instance for each queue. This achieves the queue<->napi mapping. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- include/linux/netdevice.h | 5 +++++ include/net/netdev_rx_queue.h | 2 ++ net/core/dev.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index db3d8429d50d..69e363918e4b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -657,6 +657,8 @@ struct netdev_queue { unsigned long state; + /* NAPI instance for the queue */ + struct napi_struct *napi; #ifdef CONFIG_BQL struct dql dql; #endif @@ -2618,6 +2620,9 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum netdev_queue_type type); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index cdcafb30d437..2e65b03d214d 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -21,6 +21,8 @@ struct netdev_rx_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue */ + struct napi_struct *napi; } ____cacheline_aligned_in_smp; /* diff --git a/net/core/dev.c b/net/core/dev.c index cc03a5758d2d..508b1d799681 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6394,6 +6394,40 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_napi_add_queue - Associate queue with the napi + * @napi: NAPI context + * @queue_index: Index of queue + * @type: queue type as RX or TX + * + * Add queue with its corresponding napi context + */ +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum netdev_queue_type type) +{ + struct net_device *dev = napi->dev; + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (!dev) + return -EINVAL; + + switch (type) { + case NETDEV_QUEUE_TYPE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + break; + case NETDEV_QUEUE_TYPE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + break; + default: + return -EINVAL; + } + return 0; +} +EXPORT_SYMBOL(netif_napi_add_queue); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) { From patchwork Tue Sep 19 22:27:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391976 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F32243B797 for ; Tue, 19 Sep 2023 22:15:36 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2C3E5 for ; Tue, 19 Sep 2023 15:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161733; x=1726697733; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6l+VlVuyG8bxCzRSnpu/gPQwSU+aw7PVTXnSDC6j0v0=; b=lllDYdWhJG1WceKWpUh4NYA/Mxc2h7siJTccaUmaEar7j0V2rw28Nnr5 AEYuqrXWhyJPk+V/r1/zE00jWvQVwBnT3Ck8dkoxyn+4qQU6PWXEmj3i4 L+C/q0zHacMKL10U7WTU8uY2kvPdKVue01KyrAUVWTdMevSx151Y92T9k TlwOXcmNbL8KLRDzm2QYtf5rbpdJVfQW2wTfxnnzIafEJCC/untVJMRid 8bEQLImhDaePDj8lMUgZDwY6PoNDSDNIXumfhM50hlPQwxIpjXSx9Ads0 XfYGNqyhaWlqcQsq3l4AKnn43LLBzNMWHD3fPzmOZuYniNN4HjGEYio3h w==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="382813044" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="382813044" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="1077162472" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="1077162472" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga005.fm.intel.com with ESMTP; 19 Sep 2023 15:12:02 -0700 Subject: [net-next PATCH v3 03/10] ice: Add support in the driver for associating queue with napi From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:31 -0700 Message-ID: <169516245130.7377.11908359746609369002.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org After the napi context is initialized, map the napi instance with the queue/queue-set on the corresponding irq line. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- drivers/net/ethernet/intel/ice/ice_lib.c | 57 +++++++++++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_lib.h | 4 ++ drivers/net/ethernet/intel/ice/ice_main.c | 4 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 01aa3d36b5a7..df1906566185 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2461,6 +2461,12 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params) goto unroll_vector_base; ice_vsi_map_rings_to_vectors(vsi); + + /* Associate q_vector rings to napi */ + ret = ice_vsi_add_napi_queues(vsi); + if (ret) + goto unroll_vector_base; + vsi->stat_offsets_loaded = false; if (ice_is_xdp_ena_vsi(vsi)) { @@ -2940,6 +2946,57 @@ void ice_vsi_dis_irq(struct ice_vsi *vsi) synchronize_irq(vsi->q_vectors[i]->irq.virq); } +/** + * ice_q_vector_add_napi_queues - Add queue[s] associated with the napi + * @q_vector: q_vector pointer + * + * Associate the q_vector napi with all the queue[s] on the vector + * Returns 0 on success or < 0 on error + */ +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) +{ + struct ice_rx_ring *rx_ring; + struct ice_tx_ring *tx_ring; + int ret = 0; + + ice_for_each_rx_ring(rx_ring, q_vector->rx) { + ret = netif_napi_add_queue(&q_vector->napi, rx_ring->q_index, + NETDEV_QUEUE_TYPE_RX); + if (ret) + return ret; + } + ice_for_each_tx_ring(tx_ring, q_vector->tx) { + ret = netif_napi_add_queue(&q_vector->napi, tx_ring->q_index, + NETDEV_QUEUE_TYPE_TX); + if (ret) + return ret; + } + + return ret; +} + +/** + * ice_vsi_add_napi_queues + * @vsi: VSI pointer + * + * Associate queue[s] with napi for all vectors + * Returns 0 on success or < 0 on error + */ +int ice_vsi_add_napi_queues(struct ice_vsi *vsi) +{ + int i, ret = 0; + + if (!vsi->netdev) + return ret; + + ice_for_each_q_vector(vsi, i) { + ret = ice_q_vector_add_napi_queues(vsi->q_vectors[i]); + if (ret) + return ret; + } + return ret; +} + /** * ice_vsi_release - Delete a VSI and free its resources * @vsi: the VSI being removed diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/ethernet/intel/ice/ice_lib.h index f24f5d1e6f9c..21d164ac1eed 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_lib.h @@ -91,6 +91,10 @@ void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc); struct ice_vsi * ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params); +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector); + +int ice_vsi_add_napi_queues(struct ice_vsi *vsi); + int ice_vsi_release(struct ice_vsi *vsi); void ice_vsi_close(struct ice_vsi *vsi); diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index b73d3b1e48d1..140e0e22021d 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3374,9 +3374,11 @@ static void ice_napi_add(struct ice_vsi *vsi) if (!vsi->netdev) return; - ice_for_each_q_vector(vsi, v_idx) + ice_for_each_q_vector(vsi, v_idx) { netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi, ice_napi_poll); + ice_q_vector_add_napi_queues(vsi->q_vectors[v_idx]); + } } /** From patchwork Tue Sep 19 22:27:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391974 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5747E3B29C for ; Tue, 19 Sep 2023 22:15:35 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C556F5 for ; Tue, 19 Sep 2023 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161732; x=1726697732; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zAtcdRQ//g3iTh3TX1ZLqgb/0pMs3nSTUXGPvK+SNBs=; b=Nv54z/MRDFKKIQdMTYFxTxCSTizV1Kb44XngO8/6CpiQw6GVn0HCTHfP oHFM5lDFB/rt1JQwbBWmkOCFhGNR0IHRnb0amdBP6ueZltVJkBjOIh7/Q synt+IuzkuJeojKIeE46buRJZkn97NiwMvGbEnfwGu3lGCIFQWwDh7pSR T7NScVvoSQcd4wVMB3CHKBX4VY6Kwi6KgVhp4uoj2MXXuHSmsaYA0P/Vx 57FtLUoeYhdkgRGr8PPMKkamjZJa30t6I6FR1WgKb5aswrOLGOvcGqDDs RP9KYsh1zbpYebvapABVFQ1GoIvKJc1eM2tIQtxNwQnJwmv7/RF07GjPP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="370378475" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="370378475" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="870118088" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="870118088" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 19 Sep 2023 15:12:07 -0700 Subject: [net-next PATCH v3 04/10] netdev-genl: Add netlink framework functions for queue From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:36 -0700 Message-ID: <169516245672.7377.15243846195860899954.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Implement the netdev netlink framework functions for exposing queue information. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- net/core/netdev-genl.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 3 deletions(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 336c608e6a6b..ceb7d1722f7c 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -6,9 +6,24 @@ #include #include #include +#include #include "netdev-genl-gen.h" +struct netdev_nl_dump_ctx { + unsigned long ifindex; + unsigned int rxq_idx; + unsigned int txq_idx; +}; + +static inline struct netdev_nl_dump_ctx * +netdev_dump_ctx(struct netlink_callback *cb) +{ + NL_ASSERT_DUMP_CTX_FITS(struct netdev_nl_dump_ctx); + + return (struct netdev_nl_dump_ctx *)cb->ctx; +} + static int netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, const struct genl_info *info) @@ -111,12 +126,13 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info) int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); struct net *net = sock_net(skb->sk); struct net_device *netdev; int err = 0; rtnl_lock(); - for_each_netdev_dump(net, netdev, cb->args[0]) { + for_each_netdev_dump(net, netdev, ctx->ifindex) { err = netdev_nl_dev_fill(netdev, skb, genl_info_dump(cb)); if (err < 0) break; @@ -129,14 +145,199 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int +netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, + u32 q_idx, u32 q_type, const struct genl_info *info) +{ + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + void *hdr; + + hdr = genlmsg_iput(rsp, info); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(rsp, NETDEV_A_QUEUE_Q_ID, q_idx)) + goto nla_put_failure; + + if (nla_put_u32(rsp, NETDEV_A_QUEUE_Q_TYPE, q_type)) + goto nla_put_failure; + + if (nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex)) + goto nla_put_failure; + + switch (q_type) { + case NETDEV_QUEUE_TYPE_RX: + rxq = __netif_get_rx_queue(netdev, q_idx); + if (rxq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID, + rxq->napi->napi_id)) + goto nla_put_failure; + break; + case NETDEV_QUEUE_TYPE_TX: + txq = netdev_get_tx_queue(netdev, q_idx); + if (txq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID, + txq->napi->napi_id)) + goto nla_put_failure; + + if (nla_put_u32(rsp, NETDEV_A_QUEUE_TX_MAXRATE, + txq->tx_maxrate)) + goto nla_put_failure; + break; + } + + genlmsg_end(rsp, hdr); + + return 0; + +nla_put_failure: + genlmsg_cancel(rsp, hdr); + return -EMSGSIZE; +} + +static int netdev_nl_queue_validate(struct net_device *netdev, u32 q_id, u32 q_type) +{ + switch (q_type) { + case NETDEV_QUEUE_TYPE_RX: + if (q_id >= netdev->real_num_rx_queues) + return -EINVAL; + return 0; + case NETDEV_QUEUE_TYPE_TX: + if (q_id >= netdev->real_num_tx_queues) + return -EINVAL; + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int +netdev_nl_queue_fill(struct sk_buff *rsp, struct net_device *netdev, u32 q_idx, + u32 q_type, const struct genl_info *info) +{ + int err; + + err = netdev_nl_queue_validate(netdev, q_idx, q_type); + if (err) + return err; + + return netdev_nl_queue_fill_one(rsp, netdev, q_idx, q_type, info); +} + int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + u32 q_id, q_type, ifindex; + struct net_device *netdev; + struct sk_buff *rsp; + int err; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_Q_ID)) + return -EINVAL; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_Q_TYPE)) + return -EINVAL; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) + return -EINVAL; + + q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_Q_ID]); + + q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_Q_TYPE]); + + ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); + + rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!rsp) + return -ENOMEM; + + rtnl_lock(); + + netdev = __dev_get_by_index(genl_info_net(info), ifindex); + if (netdev) + err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); + else + err = -ENODEV; + + rtnl_unlock(); + + if (err) + goto err_free_msg; + + return genlmsg_reply(rsp, info); + +err_free_msg: + nlmsg_free(rsp); + return err; +} + +static int +netdev_nl_queue_dump_one(struct net_device *netdev, struct sk_buff *rsp, + const struct genl_info *info, unsigned int *start_rx, + unsigned int *start_tx) +{ + int err = 0; + int i; + + for (i = *start_rx; i < netdev->real_num_rx_queues;) { + err = netdev_nl_queue_fill_one(rsp, netdev, i, + NETDEV_QUEUE_TYPE_RX, info); + if (err) + goto out_err; + *start_rx = i++; + } + for (i = *start_tx; i < netdev->real_num_tx_queues;) { + err = netdev_nl_queue_fill_one(rsp, netdev, i, + NETDEV_QUEUE_TYPE_TX, info); + if (err) + goto out_err; + *start_tx = i++; + } +out_err: + return err; } int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { - return -EOPNOTSUPP; + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); + const struct genl_info *info = genl_info_dump(cb); + struct net *net = sock_net(skb->sk); + unsigned int rxq_idx = ctx->rxq_idx; + unsigned int txq_idx = ctx->txq_idx; + struct net_device *netdev; + u32 ifindex = 0; + int err = 0; + + if (info->attrs[NETDEV_A_QUEUE_IFINDEX]) + ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); + + rtnl_lock(); + if (ifindex) { + netdev = __dev_get_by_index(net, ifindex); + if (netdev) + err = netdev_nl_queue_dump_one(netdev, skb, info, + &rxq_idx, &txq_idx); + else + err = -ENODEV; + } else { + for_each_netdev_dump(net, netdev, ctx->ifindex) { + err = netdev_nl_queue_dump_one(netdev, skb, info, + &rxq_idx, &txq_idx); + + if (err < 0) + break; + if (!err) { + rxq_idx = 0; + txq_idx = 0; + } + } + } + rtnl_unlock(); + + if (err != -EMSGSIZE) + return err; + + ctx->rxq_idx = rxq_idx; + ctx->txq_idx = txq_idx; + return skb->len; } static int netdev_genl_netdevice_event(struct notifier_block *nb, From patchwork Tue Sep 19 22:27:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391979 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7960F3C692 for ; Tue, 19 Sep 2023 22:15:38 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D057110 for ; Tue, 19 Sep 2023 15:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161734; x=1726697734; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QNjnfgPv+JLXGlMFGdQ4qjobnQ6tpakxT0UPcxVSq0I=; b=iU3Kyvk0E+K2Xrw1qk9k1K6xBVmLckTJVJEccezHBxXYZa4AuHAIRXwc qzOqIJStIG8HDoBb0ex13R25NcLgH3X8vwprs0NxgYzYvqe99GUBvXhnT iwfIBa/k3AnA1+cFhNPvzFl6E8aTJKvxdKEWnC/P3ZH7fDIUGcJ2lx60i zy3DetCpAHcrB+pwcPA91KPoku7gLSpdinHo6w7aw8a8e/gG7SK+qH8Kj UuzIecfyYRWhmigWjPxC/EIdeFBsIvQ5C1GgZzku60aLRglpcXFbnSk+P mjAgvvyktAD44njrIVSb7EUyK/cS/A0WO93NHyc+Yruu+1vHaZHHUb3C9 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="370378509" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="370378509" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="870118119" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="870118119" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 19 Sep 2023 15:12:13 -0700 Subject: [net-next PATCH v3 05/10] netdev-genl: spec: Extend netdev netlink spec in YAML for NAPI From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:41 -0700 Message-ID: <169516246184.7377.9186355854895330705.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for napi related information. Add code generated from the spec. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- Documentation/netlink/specs/netdev.yaml | 30 ++++++++ include/uapi/linux/netdev.h | 9 ++ net/core/netdev-genl-gen.c | 24 ++++++ net/core/netdev-genl-gen.h | 2 + net/core/netdev-genl.c | 10 +++ tools/include/uapi/linux/netdev.h | 9 ++ tools/net/ynl/generated/netdev-user.c | 124 +++++++++++++++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 75 +++++++++++++++++++ 8 files changed, 283 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 7b5d4cdff48b..446457f0c330 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -93,6 +93,19 @@ attribute-sets: enum: xdp-rx-metadata enum-as-flags: true + - + name: napi + attributes: + - + name: ifindex + doc: netdev ifindex + type: u32 + checks: + min: 1 + - + name: napi-id + doc: napi id + type: u32 - name: queue attributes: @@ -174,6 +187,23 @@ operations: attributes: - ifindex reply: *queue-get-op + - + name: napi-get + doc: napi information such as napi-id + attribute-set: napi + do: + request: + attributes: + - napi-id + reply: &napi-get-op + attributes: + - napi-id + - ifindex + dump: + request: + attributes: + - ifindex + reply: *napi-get-op mcast-groups: list: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index bb3713231b0b..96535b980065 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -69,6 +69,14 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_ID, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_A_QUEUE_Q_ID = 1, NETDEV_A_QUEUE_IFINDEX, @@ -86,6 +94,7 @@ enum { NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, NETDEV_CMD_QUEUE_GET, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c index e3632ed597b4..1ed436888e8e 100644 --- a/net/core/netdev-genl-gen.c +++ b/net/core/netdev-genl-gen.c @@ -27,6 +27,16 @@ static const struct nla_policy netdev_queue_get_dump_nl_policy[NETDEV_A_QUEUE_IF [NETDEV_A_QUEUE_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), }; +/* NETDEV_CMD_NAPI_GET - do */ +static const struct nla_policy netdev_napi_get_do_nl_policy[NETDEV_A_NAPI_NAPI_ID + 1] = { + [NETDEV_A_NAPI_NAPI_ID] = { .type = NLA_U32, }, +}; + +/* NETDEV_CMD_NAPI_GET - dump */ +static const struct nla_policy netdev_napi_get_dump_nl_policy[NETDEV_A_NAPI_IFINDEX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { { @@ -55,6 +65,20 @@ static const struct genl_split_ops netdev_nl_ops[] = { .maxattr = NETDEV_A_QUEUE_IFINDEX, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .doit = netdev_nl_napi_get_doit, + .policy = netdev_napi_get_do_nl_policy, + .maxattr = NETDEV_A_NAPI_NAPI_ID, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .dumpit = netdev_nl_napi_get_dumpit, + .policy = netdev_napi_get_dump_nl_policy, + .maxattr = NETDEV_A_NAPI_IFINDEX, + .flags = GENL_CMD_CAP_DUMP, + }, }; static const struct genl_multicast_group netdev_nl_mcgrps[] = { diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h index 263c94f77bad..ffc94956d1f5 100644 --- a/net/core/netdev-genl-gen.h +++ b/net/core/netdev-genl-gen.h @@ -16,6 +16,8 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info); +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); enum { NETDEV_NLGRP_MGMT, diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index ceb7d1722f7c..8609884fefe4 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -145,6 +145,16 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + return -EOPNOTSUPP; +} + static int netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, u32 q_idx, u32 q_type, const struct genl_info *info) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index bb3713231b0b..96535b980065 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -69,6 +69,14 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_ID, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_A_QUEUE_Q_ID = 1, NETDEV_A_QUEUE_IFINDEX, @@ -86,6 +94,7 @@ enum { NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, NETDEV_CMD_QUEUE_GET, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 749b4bea3c6c..190e17c37063 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -19,6 +19,7 @@ static const char * const netdev_op_strmap[] = { [NETDEV_CMD_DEV_DEL_NTF] = "dev-del-ntf", [NETDEV_CMD_DEV_CHANGE_NTF] = "dev-change-ntf", [NETDEV_CMD_QUEUE_GET] = "queue-get", + [NETDEV_CMD_NAPI_GET] = "napi-get", }; const char *netdev_op_str(int op) @@ -98,6 +99,16 @@ struct ynl_policy_nest netdev_queue_nest = { .table = netdev_queue_policy, }; +struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, +}; + +struct ynl_policy_nest netdev_napi_nest = { + .max_attr = NETDEV_A_NAPI_MAX, + .table = netdev_napi_policy, +}; + /* Common nested types */ /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ @@ -356,6 +367,119 @@ netdev_queue_get_dump(struct ynl_sock *ys, return NULL; } +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +void netdev_napi_get_req_free(struct netdev_napi_get_req *req) +{ + free(req); +} + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp) +{ + free(rsp); +} + +int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) +{ + struct ynl_parse_arg *yarg = data; + struct netdev_napi_get_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + unsigned int type = mnl_attr_get_type(attr); + + if (type == NETDEV_A_NAPI_NAPI_ID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.napi_id = 1; + dst->napi_id = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_IFINDEX) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.ifindex = 1; + dst->ifindex = mnl_attr_get_u32(attr); + } + } + + return MNL_CB_OK; +} + +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct netdev_napi_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + ys->req_policy = &netdev_napi_nest; + yrs.yarg.rsp_policy = &netdev_napi_nest; + + if (req->_present.napi_id) + mnl_attr_put_u32(nlh, NETDEV_A_NAPI_NAPI_ID, req->napi_id); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = netdev_napi_get_rsp_parse; + yrs.rsp_cmd = NETDEV_CMD_NAPI_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + netdev_napi_get_rsp_free(rsp); + return NULL; +} + +/* NETDEV_CMD_NAPI_GET - dump */ +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp) +{ + struct netdev_napi_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + free(rsp); + } +} + +struct netdev_napi_get_list * +netdev_napi_get_dump(struct ynl_sock *ys, struct netdev_napi_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.ys = ys; + yds.alloc_sz = sizeof(struct netdev_napi_get_list); + yds.cb = netdev_napi_get_rsp_parse; + yds.rsp_cmd = NETDEV_CMD_NAPI_GET; + yds.rsp_policy = &netdev_napi_nest; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + ys->req_policy = &netdev_napi_nest; + + if (req->_present.ifindex) + mnl_attr_put_u32(nlh, NETDEV_A_NAPI_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + netdev_napi_get_list_free(yds.first); + return NULL; +} + static const struct ynl_ntf_info netdev_ntf_info[] = { [NETDEV_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct netdev_dev_get_ntf), diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index cc938c6ba492..78b1eae9219a 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -188,4 +188,79 @@ struct netdev_queue_get_list * netdev_queue_get_dump(struct ynl_sock *ys, struct netdev_queue_get_req_dump *req); +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +struct netdev_napi_get_req { + struct { + __u32 napi_id:1; + } _present; + + __u32 napi_id; +}; + +static inline struct netdev_napi_get_req *netdev_napi_get_req_alloc(void) +{ + return calloc(1, sizeof(struct netdev_napi_get_req)); +} +void netdev_napi_get_req_free(struct netdev_napi_get_req *req); + +static inline void +netdev_napi_get_req_set_napi_id(struct netdev_napi_get_req *req, __u32 napi_id) +{ + req->_present.napi_id = 1; + req->napi_id = napi_id; +} + +struct netdev_napi_get_rsp { + struct { + __u32 napi_id:1; + __u32 ifindex:1; + } _present; + + __u32 napi_id; + __u32 ifindex; +}; + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); + +/* + * napi information such as napi-id + */ +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req); + +/* NETDEV_CMD_NAPI_GET - dump */ +struct netdev_napi_get_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct netdev_napi_get_req_dump * +netdev_napi_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct netdev_napi_get_req_dump)); +} +void netdev_napi_get_req_dump_free(struct netdev_napi_get_req_dump *req); + +static inline void +netdev_napi_get_req_dump_set_ifindex(struct netdev_napi_get_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct netdev_napi_get_list { + struct netdev_napi_get_list *next; + struct netdev_napi_get_rsp obj __attribute__ ((aligned (8))); +}; + +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp); + +struct netdev_napi_get_list * +netdev_napi_get_dump(struct ynl_sock *ys, struct netdev_napi_get_req_dump *req); + #endif /* _LINUX_NETDEV_GEN_H */ From patchwork Tue Sep 19 22:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391970 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FE473B285 for ; Tue, 19 Sep 2023 22:15:19 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13857D7 for ; Tue, 19 Sep 2023 15:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161698; x=1726697698; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ejxsKZ2HAW0bDG6Czz9bEKBgJRSE/jwj3rHWsDb57Wk=; b=co5lHg+04puJapSXh0oBzd+AZc/A5ECoclXag0g+dT7FfjzVv2YR5wkk SFMEdgH24T4fz+nIX7mdBtPvzNtW1p/f1NN7aQrCmgPH7Xpis+i+N6Fyd SppMBYvdpszXnk1++CX4jBGQDCPWquBGhU62jgJQ55MK7Gm0d2MaFjQGO 0PxyeP/cFZ3Da1A25hJ8CuBYJxIu7SQnZNxN020Hs1V8Ajifb/M9JZikt 9vd1vu50Z/SzH0FYqx0Y5yG7AYMgq1xgRwmGYeYmzysfKC0kTnmb3luvD dvc6JNH8imb90ut0FJwoRcValpRlzIIrpEY5Z7Y+YHwStFMS/7B0m8DTj A==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="383904050" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="383904050" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="696067059" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="696067059" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga003.jf.intel.com with ESMTP; 19 Sep 2023 15:12:18 -0700 Subject: [net-next PATCH v3 06/10] netdev-genl: Add netlink framework functions for napi From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:47 -0700 Message-ID: <169516246697.7377.18105000910116179893.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Implement the netdev netlink framework functions for napi support. The netdev structure tracks all the napi instances and napi fields. The napi instances and associated parameters can be retrieved this way. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- include/linux/netdevice.h | 2 + net/core/dev.c | 4 +- net/core/netdev-genl.c | 117 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 69e363918e4b..e7321178dc1a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -536,6 +536,8 @@ static inline bool napi_complete(struct napi_struct *n) return napi_complete_done(n, 0); } +struct napi_struct *napi_by_id(unsigned int napi_id); + int dev_set_threaded(struct net_device *dev, bool threaded); /** diff --git a/net/core/dev.c b/net/core/dev.c index 508b1d799681..ea6b3115ee8b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -165,7 +165,6 @@ static int netif_rx_internal(struct sk_buff *skb); static int call_netdevice_notifiers_extack(unsigned long val, struct net_device *dev, struct netlink_ext_ack *extack); -static struct napi_struct *napi_by_id(unsigned int napi_id); /* * The @dev_base_head list is protected by @dev_base_lock and the rtnl @@ -6133,7 +6132,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done) EXPORT_SYMBOL(napi_complete_done); /* must be called under rcu_read_lock(), as we dont take a reference */ -static struct napi_struct *napi_by_id(unsigned int napi_id) +struct napi_struct *napi_by_id(unsigned int napi_id) { unsigned int hash = napi_id % HASH_SIZE(napi_hash); struct napi_struct *napi; @@ -6144,6 +6143,7 @@ static struct napi_struct *napi_by_id(unsigned int napi_id) return NULL; } +EXPORT_SYMBOL(napi_by_id); #if defined(CONFIG_NET_RX_BUSY_POLL) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 8609884fefe4..6f4ed21ebd15 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "netdev-genl-gen.h" @@ -14,6 +15,7 @@ struct netdev_nl_dump_ctx { unsigned long ifindex; unsigned int rxq_idx; unsigned int txq_idx; + unsigned int napi_id; }; static inline struct netdev_nl_dump_ctx * @@ -145,14 +147,125 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int +netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, + const struct genl_info *info) +{ + void *hdr; + + if (WARN_ON_ONCE(!napi->dev)) + return -EINVAL; + + hdr = genlmsg_iput(rsp, info); + if (!hdr) + return -EMSGSIZE; + + if (napi->napi_id >= MIN_NAPI_ID && + nla_put_u32(rsp, NETDEV_A_NAPI_NAPI_ID, napi->napi_id)) + goto nla_put_failure; + + if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) + goto nla_put_failure; + + genlmsg_end(rsp, hdr); + return 0; + +nla_put_failure: + genlmsg_cancel(rsp, hdr); + return -EMSGSIZE; +} + int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + struct napi_struct *napi; + struct sk_buff *rsp; + u32 napi_id; + int err; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_NAPI_NAPI_ID)) + return -EINVAL; + + napi_id = nla_get_u32(info->attrs[NETDEV_A_NAPI_NAPI_ID]); + + rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!rsp) + return -ENOMEM; + + rtnl_lock(); + + napi = napi_by_id(napi_id); + if (napi) + err = netdev_nl_napi_fill_one(rsp, napi, info); + else + err = -EINVAL; + + rtnl_unlock(); + + if (err) + goto err_free_msg; + + return genlmsg_reply(rsp, info); + +err_free_msg: + nlmsg_free(rsp); + return err; +} + +static int +netdev_nl_napi_dump_one(struct net_device *netdev, struct sk_buff *rsp, + const struct genl_info *info, unsigned int *start) +{ + struct napi_struct *napi; + int err = 0; + + list_for_each_entry_rcu(napi, &netdev->napi_list, dev_list) { + if (*start && napi->napi_id >= *start) + continue; + + err = netdev_nl_napi_fill_one(rsp, napi, info); + if (err) + break; + *start = napi->napi_id; + } + return err; } int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { - return -EOPNOTSUPP; + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); + const struct genl_info *info = genl_info_dump(cb); + struct net *net = sock_net(skb->sk); + unsigned int n_id = ctx->napi_id; + struct net_device *netdev; + u32 ifindex = 0; + int err = 0; + + if (info->attrs[NETDEV_A_NAPI_IFINDEX]) + ifindex = nla_get_u32(info->attrs[NETDEV_A_NAPI_IFINDEX]); + + rtnl_lock(); + if (ifindex) { + netdev = __dev_get_by_index(net, ifindex); + if (netdev) + err = netdev_nl_napi_dump_one(netdev, skb, info, &n_id); + else + err = -ENODEV; + } else { + for_each_netdev_dump(net, netdev, ctx->ifindex) { + err = netdev_nl_napi_dump_one(netdev, skb, info, &n_id); + if (err < 0) + break; + if (!err) + n_id = 0; + } + } + rtnl_unlock(); + + if (err != -EMSGSIZE) + return err; + + ctx->napi_id = n_id; + return skb->len; } static int From patchwork Tue Sep 19 22:27:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391969 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C7E1262A2 for ; Tue, 19 Sep 2023 22:15:21 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DED7DD for ; Tue, 19 Sep 2023 15:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161703; x=1726697703; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kQpgC6mMaKGs++q8w17sxdCKdG2r9Ytt6fwXYyl2S6U=; b=YYkl3oaL4TaickSvU5K9LLGo5tjjFnl2ETMy8FOUIKSuHmlUb/OfmzL7 ihe1SsEDxpfKImRiw34Ntj7Sdd/Ejkdh4BHzIFoQi2b36GSirGNnjkEmw A2uMBaNzhqcP+hBO4dnvQ93Zx3+4uqhs4woWqIMGKBg2BEV/8sAJ01tJX vIIjxoiHNj+QWNolihSCKAe/pY9HsUQhnkzuKS/Uw9/eX8PYE1Vbql3YH KXfGer/8JbIXXMr2HiEIXBEQVb+cYW6g7yaFObAmK0l8LPQB+6DkMDL4S FjGBnzrX6Ak64LAUXa1leuB6EM+EA41Tm5yfqLpbZlbmTa85w9TEXE9/B w==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="383904063" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="383904063" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="696067102" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="696067102" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga003.jf.intel.com with ESMTP; 19 Sep 2023 15:12:23 -0700 Subject: [net-next PATCH v3 07/10] netdev-genl: spec: Add irq in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:52 -0700 Message-ID: <169516247209.7377.4000590042274763712.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for interrupt number among the NAPI attributes. Add code generated from the spec. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 15 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 446457f0c330..f346b1b559d9 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -106,6 +106,10 @@ attribute-sets: name: napi-id doc: napi id type: u32 + - + name: irq + doc: The associated interrupt vector number for the napi + type: u32 - name: queue attributes: @@ -199,6 +203,7 @@ operations: attributes: - napi-id - ifindex + - irq dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 96535b980065..7f626a750919 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -72,6 +72,7 @@ enum { enum { NETDEV_A_NAPI_IFINDEX = 1, NETDEV_A_NAPI_NAPI_ID, + NETDEV_A_NAPI_IRQ, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 96535b980065..7f626a750919 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -72,6 +72,7 @@ enum { enum { NETDEV_A_NAPI_IFINDEX = 1, NETDEV_A_NAPI_NAPI_ID, + NETDEV_A_NAPI_IRQ, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 190e17c37063..866fa952fdfd 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -102,6 +102,7 @@ struct ynl_policy_nest netdev_queue_nest = { struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { [NETDEV_A_NAPI_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_nest = { @@ -400,6 +401,11 @@ int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) return MNL_CB_ERROR; dst->_present.ifindex = 1; dst->ifindex = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_IRQ) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.irq = 1; + dst->irq = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 78b1eae9219a..fd3be582d933 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -215,10 +215,12 @@ struct netdev_napi_get_rsp { struct { __u32 napi_id:1; __u32 ifindex:1; + __u32 irq:1; } _present; __u32 napi_id; __u32 ifindex; + __u32 irq; }; void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); From patchwork Tue Sep 19 22:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391971 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8393B2A9 for ; Tue, 19 Sep 2023 22:15:24 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 210A218B for ; Tue, 19 Sep 2023 15:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161711; x=1726697711; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SLx8fVuZh15akXWCp9UcvFpOWOlINaD8DcuqUqy1/fM=; b=AP2pD9Ae0vrxNKhz0DRlb40MDr9KzjA2Cuk6ONO0Dt5O+DvVWHWrPjdT vzFgQLQ3KuVmnNbAyv1K65iO6R6KnHaOv3ZCZoUGM8bNIdSQPtkEtQXKa sp1PGi14FBFIRy7nqeVE7V9ZcF3q0/dr35L2YJ56k5GiNHH90HdyKS5Z9 WI2vR76uvUARFL9ABcGl6+TfEsL8kiCM2pmDqUVo1Bq4fIswk58v73l4B qGJDw8aMpH8XMd+DfBFEjwXSJf2g7kolhjMphu/lFSq3X9taiJ0yI5E+g BTw/vPIFcUo9mwcWFhbE8GDRLVESL4XRNCpB2m/OHB7rLXrDSCWQ8B5og g==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="383904077" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="383904077" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="696067142" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="696067142" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga003.jf.intel.com with ESMTP; 19 Sep 2023 15:12:28 -0700 Subject: [net-next PATCH v3 08/10] net: Add NAPI IRQ support From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:27:57 -0700 Message-ID: <169516247719.7377.5168979973638439905.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support to associate the interrupt vector number for a NAPI instance. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- drivers/net/ethernet/intel/ice/ice_lib.c | 3 +++ include/linux/netdevice.h | 6 ++++++ net/core/dev.c | 1 + net/core/netdev-genl.c | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index df1906566185..ede246720898 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2972,6 +2972,9 @@ int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) return ret; } + /* Also set the interrupt number for the NAPI */ + netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq); + return ret; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e7321178dc1a..8be6b3aa70a9 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -382,6 +382,7 @@ struct napi_struct { /* control-path-only fields follow */ struct list_head dev_list; struct hlist_node napi_hash_node; + int irq; }; enum { @@ -2625,6 +2626,11 @@ static inline void *netdev_priv(const struct net_device *dev) int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, enum netdev_queue_type type); +static inline void netif_napi_set_irq(struct napi_struct *napi, int irq) +{ + napi->irq = irq; +} + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/net/core/dev.c b/net/core/dev.c index ea6b3115ee8b..5087b0e92a59 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6463,6 +6463,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, */ if (dev->threaded && napi_kthread_create(napi)) dev->threaded = 0; + napi->irq = -1; } EXPORT_SYMBOL(netif_napi_add_weight); diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 6f4ed21ebd15..2b3818615e1b 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -167,7 +167,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) goto nla_put_failure; + if (napi->irq >= 0 && nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq)) + goto nla_put_failure; + genlmsg_end(rsp, hdr); + return 0; nla_put_failure: From patchwork Tue Sep 19 22:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391978 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDB803C684 for ; Tue, 19 Sep 2023 22:15:37 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C915DCE for ; Tue, 19 Sep 2023 15:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161734; x=1726697734; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9BqlH0iY7kzW2F/n/JSDx77imslJWCYHweR6ddNKS48=; b=D7E4zgfH5cWf+xC6n9JsXTfMyPa68o240uUq/yLbV4Z6guEoOEtXlL9L uZsO82hLXZMUt/HUyf1HBs1sZQpqtTfVp/ULN9pi/gUP0MErB8q4EXKSV TdvRiOSIrhsDoMjK8dZfFEr6Sz7dZ/TVrYD7CSuDZLws4HCGKtV/Bcj3h FRIq99x1Ehufo9DujKEpFIrsGLCDaRCe0RSHurY2xJqQv6l8smtAtC0n1 USr81I5qh0rU/RYzoAP5kHTqz1mkrJOO6U4McVWqb/dQYvs/vBeoZ2VW5 XYQK1+M9t5fNmHnBgZr3OyhIlUCnIh3DrIx1MESDbE9JxTmlJNMPi3vOC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="370378607" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="370378607" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="870118213" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="870118213" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 19 Sep 2023 15:12:33 -0700 Subject: [net-next PATCH v3 09/10] netdev-genl: spec: Add PID in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:28:02 -0700 Message-ID: <169516248230.7377.8301378959259922572.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for PID of the NAPI thread. Add code generated from the spec. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 15 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index f346b1b559d9..fc2742f1de27 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -110,6 +110,10 @@ attribute-sets: name: irq doc: The associated interrupt vector number for the napi type: u32 + - + name: pid + doc: PID of the napi thread + type: s32 - name: queue attributes: @@ -204,6 +208,7 @@ operations: - napi-id - ifindex - irq + - pid dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 7f626a750919..4a091f100982 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -73,6 +73,7 @@ enum { NETDEV_A_NAPI_IFINDEX = 1, NETDEV_A_NAPI_NAPI_ID, NETDEV_A_NAPI_IRQ, + NETDEV_A_NAPI_PID, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 7f626a750919..4a091f100982 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -73,6 +73,7 @@ enum { NETDEV_A_NAPI_IFINDEX = 1, NETDEV_A_NAPI_NAPI_ID, NETDEV_A_NAPI_IRQ, + NETDEV_A_NAPI_PID, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 866fa952fdfd..8639ece6f9a6 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -103,6 +103,7 @@ struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { [NETDEV_A_NAPI_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_PID] = { .name = "pid", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_nest = { @@ -406,6 +407,11 @@ int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) return MNL_CB_ERROR; dst->_present.irq = 1; dst->irq = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_PID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.pid = 1; + dst->pid = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index fd3be582d933..89aaee4af5d1 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -216,11 +216,13 @@ struct netdev_napi_get_rsp { __u32 napi_id:1; __u32 ifindex:1; __u32 irq:1; + __u32 pid:1; } _present; __u32 napi_id; __u32 ifindex; __u32 irq; + __s32 pid; }; void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); From patchwork Tue Sep 19 22:28:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13391972 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC803262A2 for ; Tue, 19 Sep 2023 22:15:25 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 808CD194 for ; Tue, 19 Sep 2023 15:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695161713; x=1726697713; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tTL0xnUIPkKtZCuH2wBxZi5twyVq7GcgGEVQrcNRZlg=; b=SRYGFh7Z8j04l9OQVYaufRaESfny4MuzksFyf+1n6fo4G8ZtvfHxoID9 9/bQQRHCuiaRPaALYBCiYuxP3z5UYUN2I6nphg1J6QFxC7HlUT9J4GU0j w1wzVqRA7vtE30jorRJbZOOZ7l4DmuE0NPhPSPOheH4KEvU34fh2paK6i I4nlFHQPEOANklAMEOElXlNBFy/blQyONVOEf0KNmJRuIA1Uu0bN/WM0l evuqEhkbutPkvykBLJU1EJ9OmHwGlqpkRMHLKRo+XGJntqmjojynkoO0j 5YyDYblBAmaz1CqzpUCxW14O3zwHg0B+opRHFUb9w9FjXAtznOws4923v g==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="383904104" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="383904104" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 15:12:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="781454097" X-IronPort-AV: E=Sophos;i="6.02,160,1688454000"; d="scan'208";a="781454097" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga001.jf.intel.com with ESMTP; 19 Sep 2023 15:12:38 -0700 Subject: [net-next PATCH v3 10/10] netdev-genl: Add PID for the NAPI thread From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Tue, 19 Sep 2023 15:28:07 -0700 Message-ID: <169516248742.7377.5244523678685955808.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> References: <169516206704.7377.12938469824609831999.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In the threaded NAPI mode, expose the PID of the NAPI thread. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- net/core/netdev-genl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 2b3818615e1b..369fc31a4599 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -152,6 +152,7 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, const struct genl_info *info) { void *hdr; + pid_t pid; if (WARN_ON_ONCE(!napi->dev)) return -EINVAL; @@ -170,6 +171,12 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, if (napi->irq >= 0 && nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq)) goto nla_put_failure; + if (napi->thread) { + pid = task_pid_nr(napi->thread); + if (nla_put_s32(rsp, NETDEV_A_NAPI_PID, pid)) + goto nla_put_failure; + } + genlmsg_end(rsp, hdr); return 0;