194 Commits

Author SHA1 Message Date
Stephen Hemminger
fa3949b792 rdma: add missing header for basename
The function basename prototype is in libgen.h
Fixes build on musl

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-12-12 15:22:22 -08:00
Chiara Meiohas
380a95109c rdma: Add IB device and net device rename events
rdma monitor displays the IB device name and the netdevice
name when displaying event info. Since users can modiy these
names, we track and notify on renaming events.

$ rdma monitor
$ rmmod mlx5_ib
[UNREGISTER]    dev 1  rocep8s0f1
[UNREGISTER]    dev 0  rocep8s0f0

$ modprobe mlx5_ib
[REGISTER]      dev 2  mlx5_0
[NETDEV_ATTACH] dev 2  mlx5_0 port 1 netdev 4 eth2
[REGISTER]      dev 3  mlx5_1
[NETDEV_ATTACH] dev 3  mlx5_1 port 1 netdev 5 eth3
[RENAME]        dev 2  rocep8s0f0
[RENAME]        dev 3  rocep8s0f1

$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev
[UNREGISTER]    dev 2  rocep8s0f0
[REGISTER]      dev 4  mlx5_0
[NETDEV_ATTACH] dev 4  mlx5_0 port 30 netdev 4 eth2
[RENAME]        dev 4  rdmap8s0f0

$ echo 4 > /sys/class/net/eth2/device/sriov_numvfs
[NETDEV_ATTACH] dev 4  rdmap8s0f0 port 2 netdev 7 eth4
[NETDEV_ATTACH] dev 4  rdmap8s0f0 port 3 netdev 8 eth5
[NETDEV_ATTACH] dev 4  rdmap8s0f0 port 4 netdev 9 eth6
[NETDEV_ATTACH] dev 4  rdmap8s0f0 port 5 netdev 10 eth7
[REGISTER]      dev 5  mlx5_0
[NETDEV_ATTACH] dev 5  mlx5_0 port 1 netdev 11 eth8
[REGISTER]      dev 6  mlx5_1
[NETDEV_ATTACH] dev 6  mlx5_1 port 1 netdev 12 eth9
[RENAME]        dev 5  rocep8s0f0v0
[RENAME]        dev 6  rocep8s0f0v1
[REGISTER]      dev 7  mlx5_0
[NETDEV_ATTACH] dev 7  mlx5_0 port 1 netdev 13 eth10
[RENAME]        dev 7  rocep8s0f0v2
[REGISTER]      dev 8  mlx5_0
[NETDEV_ATTACH] dev 8  mlx5_0 port 1 netdev 14 eth11
[RENAME]        dev 8  rocep8s0f0v3

$ ip link set eth2 name myeth2
[NETDEV_RENAME]	 netdev 4 myeth2

$ ip link set eth1 name myeth1

** no events received, because eth1 is not attached to
   an IB device **

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-11-16 04:38:35 +00:00
Chiara Meiohas
629e65d2fa rdma: update uapi headers
Update rdma_netlink.h file upto kernel commit 7566752e4d7d
("RDMA/nldev: Add IB device and net device rename events")

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-11-16 04:38:09 +00:00
Chiara Meiohas
be24be7405 rdma: Expose whether RDMA monitoring is supported
Extend the "rdma sys" command to display whether RDMA
monitoring is supported.

Example output for kernel where monitoring is supported:
$ rdma sys show
netns shared privileged-qkey off monitor on copy-on-fork on

Example output for kernel where monitoring is not supported:
$ rdma sys show
netns shared privileged-qkey off monitor off copy-on-fork on

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-11-16 04:38:00 +00:00
Chiara Meiohas
e0add1aff5 rdma: Add support for rdma monitor
Introduce a new command for RDMA event monitoring.
This patch adds a new attribute "event_type" which describes
the event recieved. Add a new NETLINK_RDMA multicast group
and processes listening to this multicast group receive RDMA
events.

The event types supported are IB device registration/unregistration
and net device attachment/detachment.

Example output of rdma monitor and the commands which trigger
the events:

$ rdma monitor
$ rmmod mlx5_ib
[UNREGISTER]    dev 3 rocep8s0f1
[UNREGISTER]    dev 2 rocep8s0f0

$modprobe mlx5_ib
[REGISTER]      dev 4 mlx5_0
[NETDEV_ATTACH] dev 4 mlx5_0 port 1 netdev 4 eth2
[REGISTER]      dev 5 mlx5_1
[NETDEV_ATTACH] dev 5 mlx5_1 port 1 netdev 5 eth3

$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev
[UNREGISTER]    dev 4 rocep8s0f0
[REGISTER]      dev 6 mlx5_0
[NETDEV_ATTACH] dev 6 mlx5_0 port 30 netdev 4 eth2

$ echo 4 > /sys/class/net/eth2/device/sriov_numvfs
[NETDEV_ATTACH] dev 6 rdmap8s0f0 port 2 netdev 7 eth4
[NETDEV_ATTACH] dev 6 rdmap8s0f0 port 3 netdev 8 eth5
[NETDEV_ATTACH] dev 6 rdmap8s0f0 port 4 netdev 9 eth6
[NETDEV_ATTACH] dev 6 rdmap8s0f0 port 5 netdev 10 eth7
[REGISTER]      dev 7 mlx5_0
[NETDEV_ATTACH] dev 7 mlx5_0 port 1 netdev 11 eth8
[REGISTER]      dev 8 mlx5_0
[NETDEV_ATTACH] dev 8 mlx5_0 port 1 netdev 12 eth9
[REGISTER]      dev 9 mlx5_0
[NETDEV_ATTACH] dev 9 mlx5_0 port 1 netdev 13 eth10
[REGISTER]      dev 10 mlx5_0
[NETDEV_ATTACH] dev 10 mlx5_0 port 1 netdev 14 eth11

$ echo 0 > /sys/class/net/eth2/device/sriov_numvfs
[UNREGISTER]    dev 7 rocep8s0f0v0
[UNREGISTER]    dev 8 rocep8s0f0v1
[UNREGISTER]    dev 9 rocep8s0f0v2
[UNREGISTER]    dev 10 rocep8s0f0v3
[NETDEV_DETACH] dev 6 rdmap8s0f0 port 2
[NETDEV_DETACH] dev 6 rdmap8s0f0 port 3
[NETDEV_DETACH] dev 6 rdmap8s0f0 port 4
[NETDEV_DETACH] dev 6 rdmap8s0f0 port 5

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-11-16 04:37:39 +00:00
wenglianfa
bea332466d rdma: Fix help information of 'rdma resource'
'rdma resource show cq' supports object 'dev' but not 'link', and
doesn't support device name with port.

Fixes: b0b8e32cbf ("rdma: Add CQ resource tracking information")
Signed-off-by: wenglianfa <wenglianfa@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-10-17 12:07:24 -07:00
Stephen Hemminger
b32ac38cc4 uapi: update headers
Current headers from 6.12-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-10-05 09:05:28 -07:00
Stephen Hemminger
ae32ba8273 uapi: update to 6.11-rc1
Update from 6.11-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-07-29 09:37:31 -07:00
Mark Zhang
5caf6c1764 rdma: Supports to add/delete a device with type SMI
This patch adds a new device attribute "type", as well as supports to
add and delete a rdma device with a specific type. This new device
provides a subset of functionalists defined in IBTA spec.

Currently only type "SMI" is supported: A SMI device provides SMI (QP0)
interface; This device and it's parent associates with the same HCA port
and shares the physical link, so when the parent doesn't support SMI,
It allows the subnet manager to configure the link.

This patch also supports to print device type and parent if any.

Examples:
$ rdma dev add smi1 type SMI parent ibp8s0f1
$ rdma dev show smi1
2: smi1: node_type ca fw 20.38.1002 node_guid 9803:9b03:009f:d5ef sys_image_guid 9803:9b03:009f:d5ee type smi parent ibp8s0f1
$ rdma dev del smi1

Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Acked-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-07-07 16:30:14 +00:00
Mark Zhang
ac257904ed rdma: update uapi header
Update rdma_netlink.h file upto kernel commit 294424839b5e
("RDMA/nldev: Add support to dump device type and parent device if exists")

Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Acked-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-07-07 16:30:12 +00:00
Chiara Meiohas
57d7a8fd90 rdma: Add an option to display driver-specific QPs in the rdma tool
Utilize the -dd flag (driver-specific details) in the rdmatool
to view driver-specific QPs which are not exposed yet.

The following examples show mlx5 UMR QP which is visible now:

$ rdma resource show qp link ibp8s0f1
link ibp8s0f1/1 lqpn 360 type UD state RTS sq-psn 0 comm [mlx5_ib]
link ibp8s0f1/1 lqpn 0 type SMI state RTS sq-psn 0 comm [ib_core]
link ibp8s0f1/1 lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core]

$ rdma resource show qp link ibp8s0f1 -dd
link ibp8s0f1/1 lqpn 360 type UD state RTS sq-psn 0 comm [mlx5_ib]
link ibp8s0f1/1 lqpn 465 type DRIVER subtype REG_UMR state RTS sq-psn 0 comm [mlx5_ib]
link ibp8s0f1/1 lqpn 0 type SMI state RTS sq-psn 0 comm [ib_core]
link ibp8s0f1/1 lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core]

$ rdma resource show
0: ibp8s0f0: pd 3 cq 4 qp 3 cm_id 0 mr 0 ctx 0 srq 2
1: ibp8s0f1: pd 3 cq 4 qp 3 cm_id 0 mr 0 ctx 0 srq 2

$ rdma resource show -dd
0: ibp8s0f0: pd 3 cq 4 qp 4 cm_id 0 mr 0 ctx 0 srq 2
1: ibp8s0f1: pd 3 cq 4 qp 4 cm_id 0 mr 0 ctx 0 srq 2

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-05-03 15:15:22 +00:00
Chiara Meiohas
e459ea4392 rdma: update uapi header
Update rdma_netlink.h file up to kernel commit e18fa0bbcedf
("RDMA/core: Add an option to display driver-specific QPs in the rdmatool")

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Subbaraya Sundeep <sbhatta@marvell.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2024-05-03 15:14:55 +00:00
Stephen Hemminger
0c3400cc8f spelling fixes
Use codespell and ispell to fix some spelling errors
in comments and README's.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-25 16:49:10 -08:00
wenglianfa
3a882b6b4e rdma: Fix the error of accessing string variable outside the lifecycle
All these SPRINT_BUF(b) definitions are inside the 'if' block, but
accessed outside the 'if' block through the pointers 'comm'. This
leads to empty 'comm' attribute when querying resource information.
So move the definitions to the beginning of the functions to extend
their life cycle.

Before:
$ rdma res show srq
dev hns_0 srqn 0 type BASIC lqpn 18 pdn 5 pid 7775 comm

After:
$ rdma res show srq
dev hns_0 srqn 0 type BASIC lqpn 18 pdn 5 pid 7775 comm ib_send_bw

Fixes: 1808f002df ("lib/fs: fix memory leak in get_task_name()")
Signed-off-by: wenglianfa <wenglianfa@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Acked-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-08 08:45:17 -08:00
Stephen Hemminger
a903854bad rdma: do not mix newline and json object
Mixing the semantics of ending lines with the json object
leads to several bugs where json object is closed twice, etc.
Replace by breaking the meaning of newline() function into
two parts.

Now, lots of functions were taking the rdma data structure as
argument but never using it.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
27a477ba80 rdma: add oneline flag
Add oneline output format like other commands.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
6e0d4e91a5 rdma: make supress_errors a bit
Like other command line flags supress_errors can be a bit.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
f962b24a5a rdma: make pretty behave like other commands
For tc, ip, etc the -pretty flag only has meaning if json
is used.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
22edc0cf37 rdma: use standard flag for json
The other iproute2 utils use variable json as flag.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
674e00aeab rdma: shorten print_ lines
With the shorter form of print_ function some of the lines can
now be shortened. Max line length in iproute2 should be 100 characters
or less.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-03 16:48:33 -08:00
Stephen Hemminger
9b578bbade rdma: use print_XXX instead of COLOR_NONE
The rdma utility should be using same code pattern as rest of
iproute2. When printing, color should only be requested when
desired; if no color wanted, use the simpler print_XXX instead.

Fixes: b0a688a542 ("rdma: Rewrite custom JSON and prints logic to use common API")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2024-01-01 10:46:30 -08:00
Stephen Hemminger
22f27fcb13 uapi: update headers from 6.7-rc1
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2023-11-13 08:38:58 -08:00
Patrisious Haddad
21180a7ac4 rdma: Add an option to set privileged QKEY parameter
Enrich rdmatool with an option to enable or disable privileged QKEY.
When enabled, non-privileged users will be allowed to specify a
controlled QKEY.

By default this parameter is disabled in order to comply with IB spec.
According to the IB specification rel-1.6, section 3.5.3:
"QKEYs with the most significant bit set are considered controlled
QKEYs, and a HCA does not allow a consumer to arbitrarily specify a
controlled QKEY."

This allows old applications which existed before the kernel commit:
0cadb4db79e1 ("RDMA/uverbs: Restrict usage of privileged QKEYs")
they can use privileged QKEYs without being a privileged user to now
be able to work again without being privileged granted they turn on this
parameter.

rdma tool command examples and output.

$ rdma system show
netns shared privileged-qkey off copy-on-fork on

$ rdma system set privileged-qkey on

$ rdma system show
netns shared privileged-qkey on copy-on-fork on

Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Michael Guralnik <michaelgur@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-10-26 00:05:43 +00:00
Patrisious Haddad
bbcebb2ea7 rdma: update uapi headers
Update rdma_netlink.h file upto kernel commit 36ce80759f8c
("RDMA/core: Add support to set privileged qkey parameter")

Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Michael Guralnik <michaelgur@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-10-26 00:05:41 +00:00
wenglianfa
07bfa4482d rdma: Add support to dump SRQ resource in raw format
Add support to dump SRQ resource in raw format.

This patch relies on the corresponding kernel commit aebf8145e11a
("RDMA/core: Add support to dump SRQ resource in RAW format")

Example:
$ rdma res show srq -r
dev hns3 149000...

$ rdma res show srq -j -r
[{"ifindex":0,"ifname":"hns3","data":[149,0,0,...]}]

Signed-off-by: wenglianfa <wenglianfa@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-10-16 10:15:10 -06:00
Junxian Huang
cd4315de42 rdma: Update uapi headers
Update rdma_netlink.h file upto kernel commit aebf8145e11a
("RDMA/core: Add support to dump SRQ resource in RAW format")

Signed-off-by: wenglianfa <wenglianfa@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-10-16 10:15:09 -06:00
Stephen Hemminger
5e72cc73eb Merge git://git.kernel.org/pub/scm/network/iproute2/iproute2-next 2023-06-28 08:20:57 -07:00
Stephen Hemminger
5c4697a405 whitespace cleanups
Remove trailing whitespace.
Make sure there is space after keywords.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2023-06-05 18:45:45 -07:00
Andrea Claudi
e0c7a04f1d treewide: fix indentation
Replace multiple whitespaces with tab where appropriate.
While at it, fix tc flower help message and remove some double
whitespaces.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-06-05 12:49:34 -06:00
David Ahern
efe6f2e143 Merge branch 'main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-06-05 09:18:09 -06:00
Stephen Hemminger
9c1f7f453f rdma: make rd_attr_check static
Function defined and used in only one file.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2023-06-02 09:33:34 -07:00
Stephen Hemminger
33722349fe rdma/utils: fix some analyzer warnings
Add error checks for cases where analyzer thinks it is possible
to us a possibly NULL value.

utils.c: In function ‘get_port_from_argv’:
utils.c:76:17: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
   76 |         slash = strchr(rd_argv(rd), '/');
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
  ‘get_port_from_argv’: events 1-2
    |
    |   68 | static int get_port_from_argv(struct rd *rd, uint32_t *port,
    |      |            ^~~~~~~~~~~~~~~~~~
    |      |            |
    |      |            (1) entry to ‘get_port_from_argv’
    |......
    |   76 |         slash = strchr(rd_argv(rd), '/');
    |      |                        ~
    |      |                        |
    |      |                        (2) inlined call to ‘rd_argv’ from ‘get_port_from_argv’
    |
    +--> ‘rd_argv’: event 3
           |
           |   18 |         if (!rd_argc(rd))
           |      |            ^
           |      |            |
           |      |            (3) following ‘true’ branch...
           |
    <------+
    |
  ‘get_port_from_argv’: events 4-5
    |
    |   76 |         slash = strchr(rd_argv(rd), '/');
    |      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
    |      |                 |
    |      |                 (4) ...to here
    |      |                 (5) argument 1 (‘<unknown>’) NULL where non-null expected
    |
In file included from rdma.h:10,
                 from utils.c:7:
/usr/include/string.h:246:14: note: argument 1 of ‘strchr’ must be non-null
  246 | extern char *strchr (const char *__s, int __c)
      |              ^~~~~~

Fixes: 40df8263a0 ("rdma: Add dev object")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2023-05-13 19:02:41 -07:00
Kamal Heib
bc42cde0a3 rdma: Report device protocol
Add support for reporting the device protocol.

11: mlx5_0: node_type ca protocol roce fw 12.28.2006
    node_guid 248a:0703:004b:f094 sys_image_guid 248a:0703:004b:f094
12: mlx5_1: node_type ca protocol ib fw 12.28.2006
    node_guid 248a:0703:0049:d4f0 sys_image_guid 248a:0703:0049:d4f0
13: mlx5_2: node_type ca protocol ib fw 12.28.2006
    node_guid 248a:0703:0049:d4f1 sys_image_guid 248a:0703:0049:d4f0
19: siw0: node_type rnic protocol iw node_guid 0200:00ff:fe00:0000
    sys_image_guid 0200:00ff:fe00:0000

Signed-off-by: Kamal Heib <kheib@redhat.com>
Acked-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2023-05-10 14:13:39 -06:00
Stephen Hemminger
8d7c60b4dd uapi: update headers to 6.2-rc1
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-12-26 17:57:36 -08:00
Stephen Hemminger
87dfa589f6 uapi: update headers from 6.0-rc1
These are the post-merge of netwoking user headers.
Note: this fixes compilation with gcc-12

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-08-14 19:25:21 -07:00
Stephen Hemminger
71178ae0ff rdma: update uapi/ib_user_verbs.h
Update from 5.19-rc7

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-07-18 09:58:28 -07:00
Andrea Claudi
93fb6810e1 Makefile: move HAVE_MNL check to top-level Makefile
dcb, devlink, rdma, tipc and vdpa rely on libmnl to compile, so they
check for libmnl to be installed on their Makefiles.

This moves HAVE_MNL check from the tools to top-level Makefile, thus
avoiding to call their Makefiles if libmnl is not present.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2022-03-12 09:00:56 -07:00
Andrea Claudi
ac0a54b2d5 rdma: make RES_PID and RES_KERN_NAME alternative to each other
RDMA_NLDEV_ATTR_RES_PID and RDMA_NLDEV_ATTR_RES_KERN_NAME cannot be set
together, as evident for the fill_res_name_pid() function in the kernel
infiniband driver. This commit makes this clear at first glance, using
an else branch for the RDMA_NLDEV_ATTR_RES_KERN_NAME case.

This also helps coverity to better understand this code and avoid
producing a bogus warning complaining about mnl_attr_get_str overwriting
comme, and thus leaking the storage that comm points to.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-03-11 19:16:50 -08:00
Andrea Claudi
1808f002df lib/fs: fix memory leak in get_task_name()
asprintf() allocates memory which is not freed on the error path of
get_task_name(), thus potentially leading to memory leaks.
%m specifier on fscanf allocates memory, too, which needs to be freed by
the caller.

This reworks get_task_name() to avoid memory allocation.
- Pass a buffer and its length to the function, similarly to what
  get_command_name() does, thus avoiding to allocate memory for
  the string to be returned;
- Use snprintf() instead of asprintf();
- Use fgets() instead of fscanf() to limit string length.

Fixes: 81bfd01a4c ("lib: move get_task_name() from rdma")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-03-11 19:10:48 -08:00
Shangyan Zhou
c8d9d92544 rdma: Fix the logic to print unsigned int.
Use the corresponding function and fmt string to print unsigned int32
and int64.

Signed-off-by: Shangyan Zhou <sy.zhou@hotmail.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-03-07 11:27:13 -08:00
Stephen Hemminger
a42dfaa46e Revert "rdma: Fix res_print_uint() and add res_print_u64()"
This reverts commit 9d0badecea.
2022-03-07 11:27:07 -08:00
Shangyan Zhou
9d0badecea rdma: Fix res_print_uint() and add res_print_u64()
Use the corresponding function and fmt string to print unsigned int32
and int64.

Signed-off-by: Shangyan Zhou <sy.zhou@hotmail.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-03-04 14:26:49 -08:00
Leon Romanovsky
bb4cc9cca4 rdma: Don't allocate sparse array
The addition of driver QP type with index 0xFF caused to the following
clang compilation error:

res.c:152:10: warning: result of comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
        if (idx < ARRAY_SIZE(qp_types_str) && qp_types_str[idx])
            ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~

Instead of allocating very sparse array, simply create separate check
for the driver QP type.

Fixes: 39307384ce ("rdma: Add driver QP type string")
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2022-01-11 09:19:27 -07:00
Leon Romanovsky
b87671681e rdma: Limit copy data by the destination size
The strncat() function will copy upto n bytes supplied as third
argument. The n bytes shouldn't be no more than destination and
not the source.

This change fixes the following clang compilation warnings:

res-srq.c:75:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
                        strncat(qp_str, tmp, sizeof(tmp) - 1);
                                             ^~~~~~~~~~~~~~~
res-srq.c:99:23: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
        strncat(qp_str, tmp, sizeof(tmp) - 1);
                             ^~~~~~~~~~~~~~~
res-srq.c:142:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
                        strncat(qp_str, tmp, sizeof(tmp) - 1);
                                             ^~~~~~~~~~~~~~~

Fixes: 9b272e138d ("rdma: Add SRQ resource tracking information")
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2022-01-11 09:18:16 -07:00
Stephen Hemminger
79026c1262 rdma: update uapi headers
Update the RDMA uapi headers from 5.16.0-rc1

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2021-11-18 10:00:19 -08:00
David Ahern
50b668bdbf Merge branch 'main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
2021-11-04 09:45:31 -06:00
Neta Ostrovsky
ad3a118f88 rdma: Fix SRQ resource tracking information json
Fix the json output for the QPs that are associated with the SRQ -
The qpn are now displayed in a json array.

Sample output before the fix:
$ rdma res show srq lqpn 126-141 -j -p
[ {
        "ifindex":0,
	"ifname":"ibp8s0f0",
	"srqn":4,
	"type":"BASIC",
	"lqpn":["126-128,130-140"],
	"pdn":9,
	"pid":3581,
	"comm":"ibv_srq_pingpon"
    },{
	"ifindex":0,
	"ifname":"ibp8s0f0",
	"srqn":5,
	"type":"BASIC",
	"lqpn":["141"],
	"pdn":10,
	"pid":3584,
	"comm":"ibv_srq_pingpon"
    } ]

Sample output after the fix:
$ rdma res show srq lqpn 126-141 -j -p
[ {
        "ifindex":0,
	"ifname":"ibp8s0f0",
	"srqn":4,
	"type":"BASIC",
	"lqpn":["126-128","130-140"],
	"pdn":9,
	"pid":3581,
	"comm":"ibv_srq_pingpon"
    },{
	"ifindex":0,
	"ifname":"ibp8s0f0",
	"srqn":5,
	"type":"BASIC",
	"lqpn":["141"],
	"pdn":10,
	"pid":3584,
	"comm":"ibv_srq_pingpon"
    } ]

Fixes: 9b272e138d ("rdma: Add SRQ resource tracking information")
Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2021-10-29 15:04:45 -07:00
Neta Ostrovsky
19ba785f16 rdma: Add optional-counters set/unset support
This patch provides an extension to the rdma statistics tool
that allows to set/unset optional counters set dynamically,
using new netlink commands.
Note that the optional counter statistic implementation is
driver-specific and may impact the performance.

Examples:
To enable a set of optional counters on link rocep8s0f0/1:
    $ sudo rdma statistic set link rocep8s0f0/1 optional-counters cc_rx_ce_pkts,cc_rx_cnp_pkts
To disable all optional counters on link rocep8s0f0/1:
    $ sudo rdma statistic unset link rocep8s0f0/1 optional-counters

Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2021-10-15 17:52:57 -06:00
Neta Ostrovsky
7d5cb70e94 rdma: Add stat "mode" support
This patch introduces the "mode" command, which presents the enabled or
supported (when the "supported" argument is available) optional
counters.

An optional counter is a vendor-specific counter that may be
dynamically enabled/disabled. This enhancement of hwcounters allows
exposing of counters which are for example mutual exclusive and cannot
be enabled at the same time, counters that might degrades performance,
optional debug counters, etc.

Examples:
To present currently enabled optional counters on link rocep8s0f0/1:
    $ rdma statistic mode link rocep8s0f0/1
    link rocep8s0f0/1 optional-counters cc_rx_ce_pkts

To present supported optional counters on link rocep8s0f0/1:
    $ rdma statistic mode supported link rocep8s0f0/1
    link rocep8s0f0/1 supported optional-counters cc_rx_ce_pkts,cc_rx_cnp_pkts,cc_tx_cnp_pkts

Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2021-10-15 17:52:53 -06:00
Neta Ostrovsky
d480cb71f5 rdma: Update uapi headers
Update rdma_netlink.h file upto kernel commit 7301d0a9834c
("RDMA/nldev: Add support to get status of all counters")

Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
2021-10-15 17:52:47 -06:00