Commit Graph

121 Commits

Author SHA1 Message Date
Petr Oros f4281a7f48 netdevsim: avoid potential loop in nsim_dev_trap_report_work()
JIRA: https://issues.redhat.com/browse/RHEL-38987

Upstream commit(s):
commit ba5e1272142d051dcc57ca1d3225ad8a089f9858
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Feb 1 17:53:24 2024 +0000

    netdevsim: avoid potential loop in nsim_dev_trap_report_work()

    Many syzbot reports include the following trace [1]

    If nsim_dev_trap_report_work() can not grab the mutex,
    it should rearm itself at least one jiffie later.

    [1]
    Sending NMI from CPU 1 to CPUs 0:
    NMI backtrace for cpu 0
    CPU: 0 PID: 32383 Comm: kworker/0:2 Not tainted 6.8.0-rc2-syzkaller-00031-g861c0981648f #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/17/2023
    Workqueue: events nsim_dev_trap_report_work
     RIP: 0010:bytes_is_nonzero mm/kasan/generic.c:89 [inline]
     RIP: 0010:memory_is_nonzero mm/kasan/generic.c:104 [inline]
     RIP: 0010:memory_is_poisoned_n mm/kasan/generic.c:129 [inline]
     RIP: 0010:memory_is_poisoned mm/kasan/generic.c:161 [inline]
     RIP: 0010:check_region_inline mm/kasan/generic.c:180 [inline]
     RIP: 0010:kasan_check_range+0x101/0x190 mm/kasan/generic.c:189
    Code: 07 49 39 d1 75 0a 45 3a 11 b8 01 00 00 00 7c 0b 44 89 c2 e8 21 ed ff ff 83 f0 01 5b 5d 41 5c c3 48 85 d2 74 4f 48 01 ea eb 09 <48> 83 c0 01 48 39 d0 74 41 80 38 00 74 f2 eb b6 41 bc 08 00 00 00
    RSP: 0018:ffffc90012dcf998 EFLAGS: 00000046
    RAX: fffffbfff258af1e RBX: fffffbfff258af1f RCX: ffffffff8168eda3
    RDX: fffffbfff258af1f RSI: 0000000000000004 RDI: ffffffff92c578f0
    RBP: fffffbfff258af1e R08: 0000000000000000 R09: fffffbfff258af1e
    R10: ffffffff92c578f3 R11: ffffffff8acbcbc0 R12: 0000000000000002
    R13: ffff88806db38400 R14: 1ffff920025b9f42 R15: ffffffff92c578e8
    FS:  0000000000000000(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 000000c00994e078 CR3: 000000002c250000 CR4: 00000000003506f0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
     <NMI>
     </NMI>
     <TASK>
      instrument_atomic_read include/linux/instrumented.h:68 [inline]
      atomic_read include/linux/atomic/atomic-instrumented.h:32 [inline]
      queued_spin_is_locked include/asm-generic/qspinlock.h:57 [inline]
      debug_spin_unlock kernel/locking/spinlock_debug.c:101 [inline]
      do_raw_spin_unlock+0x53/0x230 kernel/locking/spinlock_debug.c:141
      __raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:150 [inline]
      _raw_spin_unlock_irqrestore+0x22/0x70 kernel/locking/spinlock.c:194
      debug_object_activate+0x349/0x540 lib/debugobjects.c:726
      debug_work_activate kernel/workqueue.c:578 [inline]
      insert_work+0x30/0x230 kernel/workqueue.c:1650
      __queue_work+0x62e/0x11d0 kernel/workqueue.c:1802
      __queue_delayed_work+0x1bf/0x270 kernel/workqueue.c:1953
      queue_delayed_work_on+0x106/0x130 kernel/workqueue.c:1989
      queue_delayed_work include/linux/workqueue.h:563 [inline]
      schedule_delayed_work include/linux/workqueue.h:677 [inline]
      nsim_dev_trap_report_work+0x9c0/0xc80 drivers/net/netdevsim/dev.c:842
      process_one_work+0x886/0x15d0 kernel/workqueue.c:2633
      process_scheduled_works kernel/workqueue.c:2706 [inline]
      worker_thread+0x8b9/0x1290 kernel/workqueue.c:2787
      kthread+0x2c6/0x3a0 kernel/kthread.c:388
      ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
      ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:242
     </TASK>

    Fixes: 012ec02ae441 ("netdevsim: convert driver to use unlocked devlink API during init/fini")
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Link: https://lore.kernel.org/r/20240201175324.3752746-1-edumazet@google.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2024-05-28 13:35:19 +02:00
Petr Oros 989e0e1cb4 netdevsim: fix uninitialized data in nsim_dev_trap_fa_cookie_write()
JIRA: https://issues.redhat.com/browse/RHEL-38987

Upstream commit(s):
commit f72207a5c0dbaaf6921cf9a6c0d2fd0bc249ea78
Author: Dan Carpenter <dan.carpenter@linaro.org>
Date:   Tue Jul 11 11:52:26 2023 +0300

    netdevsim: fix uninitialized data in nsim_dev_trap_fa_cookie_write()

    The simple_write_to_buffer() function is designed to handle partial
    writes.  It returns negatives on error, otherwise it returns the number
    of bytes that were able to be copied.  This code doesn't check the
    return properly.  We only know that the first byte is written, the rest
    of the buffer might be uninitialized.

    There is no need to use the simple_write_to_buffer() function.
    Partial writes are prohibited by the "if (*ppos != 0)" check at the
    start of the function.  Just use memdup_user() and copy the whole
    buffer.

    Fixes: d3cbb907ae ("netdevsim: add ACL trap reporting cookie as a metadata")
    Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
    Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
    Reviewed-by: Ido Schimmel <idosch@nvidia.com>
    Link: https://lore.kernel.org/r/7c1f950b-3a7d-4252-82a6-876e53078ef7@moroto.mountain
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2024-05-28 13:35:18 +02:00
Jan Stancek 8e94775eed Merge: CNB: rebase/update devlink for RHEL 9.3
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2191

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273
Tested: selftests, basic devlink features on ice and mlx5
Depends: https://bugzilla.redhat.com/show_bug.cgi?id=2175249
Depends: https://bugzilla.redhat.com/show_bug.cgi?id=2175250
Depends: https://bugzilla.redhat.com/show_bug.cgi?id=2176150

Update devlink up to v6.3.

Signed-off-by: Petr Oros <poros@redhat.com>

Approved-by: Ivan Vecera <ivecera@redhat.com>
Approved-by: Íñigo Huguet <ihuguet@redhat.com>
Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com>
Approved-by: Herbert Xu <zxu@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-04-27 07:47:22 +02:00
Petr Oros 2adb8b0b2c devlink: remove devlink features
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Conflicts:
-  Unmerged, because file missing in rhel:
    drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c
    drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c

Upstream commit(s):
commit fb8421a94c5613fee86e192bab0892ecb1d56e4c
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Fri Jan 27 16:50:42 2023 +0100

    devlink: remove devlink features

    Devlink features were introduced to disallow devlink reload calls of
    userspace before the devlink was fully initialized. The reason for this
    workaround was the fact that devlink reload was originally called
    without devlink instance lock held.

    However, with recent changes that converted devlink reload to be
    performed under devlink instance lock, this is redundant so remove
    devlink features entirely.

    Note that mlx5 used this to enable devlink reload conditionally only
    when device didn't act as multi port slave. Move the multi port check
    into mlx5_devlink_reload_down() callback alongside with the other
    checks preventing the device from reload in certain states.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-04 11:12:22 +02:00
Petr Oros d8b98e9e7f devlink: protect devlink param list by instance lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Upstream commit(s):
commit 075935f0ae0fbbe469a911d685f6cc59de892700
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Thu Jan 26 08:58:35 2023 +0100

    devlink: protect devlink param list by instance lock

    Commit 1d18bb1a4ddd ("devlink: allow registering parameters after
    the instance") as the subject implies introduced possibility to register
    devlink params even for already registered devlink instance. This is a
    bit problematic, as the consistency or params list was originally
    secured by the fact it is static during devlink lifetime. So in order to
    protect the params list, take devlink instance lock during the params
    operations. Introduce unlocked function variants and use them in drivers
    in locked context. Put lock assertions to appropriate places.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Reviewed-by: Jakub Kicinski <kuba@kernel.org>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Reviewed-by: Ido Schimmel <idosch@nvidia.com>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Tested-by: Simon Horman <simon.horman@corigine.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-04 11:12:21 +02:00
Petr Oros a612d09016 netdevsim: move devlink registration under the instance lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Upstream commit(s):
commit 82a3aef2e6af2fdd04d542c83b7a35990d94afc9
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Jan 5 22:34:02 2023 -0800

    netdevsim: move devlink registration under the instance lock

    To prevent races with netdev code accessing free devlink instances
    move the registration under the devlink instance lock.
    Core now waits for the instance to be registered before accessing it.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-03 14:06:08 +02:00
Petr Oros f1a3589e8d netdevsim: rename a label
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Upstream commit(s):
commit 5c5ea1d09fd8aec8319d629df47a581bd19f8f91
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Jan 5 22:34:01 2023 -0800

    netdevsim: rename a label

    err_dl_unregister should unregister the devlink instance.
    Looks like renaming it was missed in one of the reshufflings.

    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-03 14:06:08 +02:00
Petr Oros 2c8dee9554 net: devlink: let the core report the driver name instead of the drivers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Conflicts:
-  drivers/ptp/ptp_ocp.c: chunk skipped due to missing
   773bda96492153 ("ptp: ocp: Expose various resources on the
   timecard.")
-  Unmerged, because file missing in rhel:
    drivers/net/ethernet/fungible/funeth/funeth_devlink.c
    drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
    drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c

Upstream commit(s):
commit 226bf980550627c88549b112ac6c8fb40873afb4
Author: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Date:   Tue Nov 29 18:51:38 2022 +0900

    net: devlink: let the core report the driver name instead of the drivers

    The driver name is available in device_driver::name. Right now,
    drivers still have to report this piece of information themselves in
    their devlink_ops::info_get callback function.

    In order to factorize code, make devlink_nl_info_fill() add the driver
    name attribute.

    Now that the core sets the driver name attribute, drivers are not
    supposed to call devlink_info_driver_name_put() anymore. Remove
    devlink_info_driver_name_put() and clean-up all the drivers using this
    function in their callback.

    Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
    Tested-by: Ido Schimmel <idosch@nvidia.com> # mlxsw
    Reviewed-by: Jacob Keller  <jacob.e.keller@intel.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-03 14:06:02 +02:00
Petr Oros 8a26129ffe devlink: Allow to set up parent in devl_rate_leaf_create()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Upstream commit(s):
commit f2fc15e271f2d17f2bee2c5a3b3e50252a7ba91f
Author: Michal Wilczynski <michal.wilczynski@intel.com>
Date:   Tue Nov 15 11:48:19 2022 +0100

    devlink: Allow to set up parent in devl_rate_leaf_create()

    Currently the driver is able to create leaf nodes for the devlink-rate,
    but is unable to set parent for them. This wasn't as issue before the
    possibility to export hierarchy from the driver. After adding the export
    feature, in order for the driver to supply correct hierarchy, it's
    necessary for it to be able to supply a parent name to
    devl_rate_leaf_create().

    Introduce a new parameter 'parent_name' in devl_rate_leaf_create().

    Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-03 14:06:00 +02:00
Petr Oros 7bb2823ab1 net: make drivers to use SET_NETDEV_DEVLINK_PORT to set devlink_port
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172273

Conflicts:
- drivers/net/ethernet/mellanox/mlxsw/core.c: adjusted context conflicts
  due to missing 3471ac9b22c18a ("mlxsw: Remove unused IB stuff")
- drivers/net/ethernet/mellanox/mlxsw/spectrum.c: adjusted context
  conflicts due to missing a159e986ad26d3 ("mlxsw: spectrum: Clear PTP
  configuration after unregistering the netdevice")
- drivers/net/ethernet/marvell/prestera/prestera_main.c: adjusted context
  conflict due to missing 52323ef75414d6 ("net: marvell: prestera:
  add phylink support")
- drivers/net/ethernet/mscc/ocelot_vsc7514.c: adjusted context conflict
  due to missing e6e12df625f23e net: mscc: ocelot: convert to phylink
- drivers/net/ethernet/ti/am65-cpsw-nuss.c: skipped chunk due to
  missing 0680e20af5fbf4 ("net: ethernet: ti: am65-cpsw: Fix devlink
  port register sequence")
- drivers/net/ethernet/fungible/funeth/funeth_main.c: unmerged path
  because file missing in RHEL

Upstream commit(s):
commit ac73d4bf2cdaf2cb8a43df8ee4a5c066d2c5d7b4
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Wed Nov 2 17:02:04 2022 +0100

    net: make drivers to use SET_NETDEV_DEVLINK_PORT to set devlink_port

    Benefit from the previously implemented tracking of netdev events in
    devlink code and instead of calling  devlink_port_type_eth_set() and
    devlink_port_type_clear() to set devlink port type and link to related
    netdev, use SET_NETDEV_DEVLINK_PORT() macro to assign devlink_port
    pointer to netdevice which is about to be registered.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-04-03 10:57:13 +02:00
Petr Oros 6a5dfbb0be netdevsim: Fix memory leak of nsim_dev->fa_cookie
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181505

Upstream commit(s):
commit 064bc7312bd09a48798418663090be0c776183db
Author: Wang Yufen <wangyufen@huawei.com>
Date:   Tue Nov 15 17:30:25 2022 +0800

    netdevsim: Fix memory leak of nsim_dev->fa_cookie

    kmemleak reports this issue:

    unreferenced object 0xffff8881bac872d0 (size 8):
      comm "sh", pid 58603, jiffies 4481524462 (age 68.065s)
      hex dump (first 8 bytes):
        04 00 00 00 de ad be ef                          ........
      backtrace:
        [<00000000c80b8577>] __kmalloc+0x49/0x150
        [<000000005292b8c6>] nsim_dev_trap_fa_cookie_write+0xc1/0x210 [netdevsim]
        [<0000000093d78e77>] full_proxy_write+0xf3/0x180
        [<000000005a662c16>] vfs_write+0x1c5/0xaf0
        [<000000007aabf84a>] ksys_write+0xed/0x1c0
        [<000000005f1d2e47>] do_syscall_64+0x3b/0x90
        [<000000006001c6ec>] entry_SYSCALL_64_after_hwframe+0x63/0xcd

    The issue occurs in the following scenarios:

    nsim_dev_trap_fa_cookie_write()
      kmalloc() fa_cookie
      nsim_dev->fa_cookie = fa_cookie
    ..
    nsim_drv_remove()

    The fa_cookie allocked in nsim_dev_trap_fa_cookie_write() is not freed. To
    fix, add kfree(nsim_dev->fa_cookie) to nsim_drv_remove().

    Fixes: d3cbb907ae ("netdevsim: add ACL trap reporting cookie as a metadata")
    Signed-off-by: Wang Yufen <wangyufen@huawei.com>
    Cc: Jiri Pirko <jiri@mellanox.com>
    Link: https://lore.kernel.org/r/1668504625-14698-1-git-send-email-wangyufen@huawei.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-03-24 11:37:26 +01:00
Petr Oros d9fcbbc2a5 netdevsim: remove dir in nsim_dev_debugfs_init() when creating ports dir failed
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181505

Upstream commit(s):
commit a6aa8d0ce2cfba57ac0f23293fcb3be0b9f53fba
Author: Zhengchao Shao <shaozhengchao@huawei.com>
Date:   Wed Oct 26 09:46:42 2022 +0800

    netdevsim: remove dir in nsim_dev_debugfs_init() when creating ports dir failed

    Remove dir in nsim_dev_debugfs_init() when creating ports dir failed.
    Otherwise, the netdevsim device will not be created next time. Kernel
    reports an error: debugfs: Directory 'netdevsim1' with parent 'netdevsim'
    already present!

    Fixes: ab1d0cc004 ("netdevsim: change debugfs tree topology")
    Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-03-24 11:37:25 +01:00
Petr Oros b2c619b7a6 netdevsim: fix memory leak in nsim_drv_probe() when nsim_dev_resources_register() failed
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181505

Upstream commit(s):
commit 6b1da9f7126f05e857da6db24c6a04aa7974d644
Author: Zhengchao Shao <shaozhengchao@huawei.com>
Date:   Wed Oct 26 09:46:41 2022 +0800

    netdevsim: fix memory leak in nsim_drv_probe() when nsim_dev_resources_register() failed

    If some items in nsim_dev_resources_register() fail, memory leak will
    occur. The following is the memory leak information.

    unreferenced object 0xffff888074c02600 (size 128):
      comm "echo", pid 8159, jiffies 4294945184 (age 493.530s)
      hex dump (first 32 bytes):
        40 47 ea 89 ff ff ff ff 01 00 00 00 00 00 00 00  @G..............
        ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
      backtrace:
        [<0000000011a31c98>] kmalloc_trace+0x22/0x60
        [<0000000027384c69>] devl_resource_register+0x144/0x4e0
        [<00000000a16db248>] nsim_drv_probe+0x37a/0x1260
        [<000000007d1f448c>] really_probe+0x20b/0xb10
        [<00000000c416848a>] __driver_probe_device+0x1b3/0x4a0
        [<00000000077e0351>] driver_probe_device+0x49/0x140
        [<0000000054f2465a>] __device_attach_driver+0x18c/0x2a0
        [<000000008538f359>] bus_for_each_drv+0x151/0x1d0
        [<0000000038e09747>] __device_attach+0x1c9/0x4e0
        [<00000000dd86e533>] bus_probe_device+0x1d5/0x280
        [<00000000839bea35>] device_add+0xae0/0x1cb0
        [<000000009c2abf46>] new_device_store+0x3b6/0x5f0
        [<00000000fb823d7f>] bus_attr_store+0x72/0xa0
        [<000000007acc4295>] sysfs_kf_write+0x106/0x160
        [<000000005f50cb4d>] kernfs_fop_write_iter+0x3a8/0x5a0
        [<0000000075eb41bf>] vfs_write+0x8f0/0xc80

    Fixes: 37923ed6b8 ("netdevsim: Add simple FIB resource controller via devlink")
    Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-03-24 11:37:25 +01:00
Petr Oros 7ed6c05934 netdevsim: remove redundant variable ret
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181505

Upstream commit(s):
commit 5603072e0b3733c076529e49ee3150cbb3a7a5cc
Author: Jinpeng Cui <cui.jinpeng2@zte.com.cn>
Date:   Wed Aug 31 15:43:29 2022 +0000

    netdevsim: remove redundant variable ret

    Return value directly from nsim_dev_reload_create()
    instead of getting value from redundant variable ret.

    Reported-by: Zeal Robot <zealci@zte.com.cn>
    Signed-off-by: Jinpeng Cui <cui.jinpeng2@zte.com.cn>
    Link: https://lore.kernel.org/r/20220831154329.305372-1-cui.jinpeng2@zte.com.cn
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-03-24 11:37:25 +01:00
Petr Oros ff020891f8 net: devlink: limit flash component name to match version returned by info_get()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2131117

Upstream commit(s):
commit f94b606325c194adadaee2265b4db990802c4850
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Wed Aug 24 14:20:11 2022 +0200

    net: devlink: limit flash component name to match version returned by info_get()

    Limit the acceptance of component name passed to cmd_flash_update() to
    match one of the versions returned by info_get(), marked by version type.
    This makes things clearer and enforces 1:1 mapping between exposed
    version and accepted flash component.

    Check VERSION_TYPE_COMPONENT version type during cmd_flash_update()
    execution by calling info_get() with different "req" context.
    That causes info_get() to lookup the component name instead of
    filling-up the netlink message.

    Remove "UPDATE_COMPONENT" flag which becomes used.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-01-18 14:54:03 +01:00
Petr Oros fbb5e9da6d netdevsim: add version fw.mgmt info info_get() and mark as a component
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2131117

Upstream commit(s):
commit 0c1989754f76b52bd30581ff543890cab8c75a9d
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Wed Aug 24 14:20:10 2022 +0200

    netdevsim: add version fw.mgmt info info_get() and mark as a component

    Fix the only component user which is netdevsim. It uses component named
    "fw.mgmt" in selftests. So add this version to info_get() output with
    version type component.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-01-18 14:54:03 +01:00
Petr Oros 31a499f90b net: devlink: convert reload command to take implicit devlink->lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2131117

Upstream commit(s):
commit 644a66c60f02f302d82c3008ae2ffe67cf495383
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Fri Jul 29 09:10:36 2022 +0200

    net: devlink: convert reload command to take implicit devlink->lock

    Convert reload command to behave the same way as the rest of the
    commands and let if be called with devlink->lock held. Remove the
    temporary devl_lock taking from drivers. As the DEVLINK_NL_FLAG_NO_LOCK
    flag is no longer used, remove it alongside.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-01-18 14:54:02 +01:00
Petr Oros 57497ee6eb netdevsim: convert driver to use unlocked devlink API during init/fini
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2131117

Upstream commit(s):
commit 012ec02ae4410207f796a9b280a60b80b6cc790a
Author: Jiri Pirko <jiri@nvidia.com>
Date:   Sat Jul 16 13:02:40 2022 +0200

    netdevsim: convert driver to use unlocked devlink API during init/fini

    Prepare for devlink reload being called with devlink->lock held and
    convert the netdevsim driver to use unlocked devlink API during init and
    fini flows. Take devl_lock() in reload_down() and reload_up() ops in the
    meantime before reload cmd is converted to take the lock itself.

    Signed-off-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-01-18 14:54:00 +01:00
Ivan Vecera 6a03fa2a91 netdevsim: Introduce support for L3 offload xstats
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2140149

commit 1a6d7ae7d63c4572676f4cc94aa35a73dc14a757
Author: Petr Machata <petrm@nvidia.com>
Date:   Mon Mar 14 15:01:15 2022 +0100

    netdevsim: Introduce support for L3 offload xstats

    Add support for testing of HW stats support that was added recently, namely
    the L3 stats support. L3 stats are provided for devices for which the L3
    stats have been turned on, and that were enabled for netdevsim through a
    debugfs toggle:

        # echo $ifindex > /sys/kernel/debug/netdevsim/$DEV/hwstats/l3/enable_ifindex

    For fully enabled netdevices, netdevsim counts 10pps of ingress traffic and
    20pps of egress traffic. Similarly, L3 stats can be disabled for a given
    device, and netdevsim ceases pretending there is any HW traffic going on:

        # echo $ifindex > /sys/kernel/debug/netdevsim/$DEV/hwstats/l3/disable_ifindex

    Besides this, there is a third toggle to mark a device for future failure:

        # echo $ifindex > /sys/kernel/debug/netdevsim/$DEV/hwstats/l3/fail_next_enable

    A future request to enable L3 stats on such netdevice will be bounced by
    netdevsim:

        # ip -j l sh dev d | jq '.[].ifindex'
        66
        # echo 66 > /sys/kernel/debug/netdevsim/netdevsim10/hwstats/l3/enable_ifindex
        # echo 66 > /sys/kernel/debug/netdevsim/netdevsim10/hwstats/l3/fail_next_enable
        # ip stats set dev d l3_stats on
        Error: netdevsim: Stats enablement set to fail.

    Signed-off-by: Petr Machata <petrm@nvidia.com>
    Reviewed-by: Ido Schimmel <idosch@nvidia.com>
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2022-11-04 17:25:41 +01:00
Petr Oros 24b38c8b0b devlink: hold the instance lock during eswitch_mode callbacks
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2101713

Upstream commit(s):
commit 14e426bf1a4d77ac87d0fa2a964092a23f863e44
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Fri Mar 18 12:23:44 2022 -0700

    devlink: hold the instance lock during eswitch_mode callbacks

    Make the devlink core hold the instance lock during eswitch_mode
    callbacks. Cheat in case of mlx5 (see the cover letter).

    Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-08-22 22:07:29 +02:00
Petr Oros 6742a09c44 netdevsim: replace vfs_lock with devlink instance lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2101713

Upstream commit(s):
commit aff3a925094633a5b77058b9a715efbb12fc2698
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Fri Mar 18 12:23:43 2022 -0700

    netdevsim: replace vfs_lock with devlink instance lock

    Similarly to the previous commit, use the devlink instance
    lock and let it replace the vfs_lock.

    nsim_esw_legacy_enable() was locked by both port lock and
    vfs lock so one set of lock/unlocks goes away.

    netdevsim's .eswitch_mode_set callback is now ready for
    the callback to take the instance lock.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-08-22 22:05:25 +02:00
Petr Oros 6d57a616e0 netdevsim: replace port_list_lock with devlink instance lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2101713

Upstream commit(s):
commit 76eea6c2e663f7e9fbc258c82811ad9e657e085f
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Fri Mar 18 12:23:42 2022 -0700

    netdevsim: replace port_list_lock with devlink instance lock

    Take advantage of the devlink instance lock for protecting
    the port list. This will simplify locking even more once
    all devlink callbacks hold the instance lock.

    We need to add locking in nsim_dev_port_add_all() which used
    to assume higher layer protection when accessing the list.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-08-22 22:05:25 +02:00
Petr Oros f42c843bba netdevsim: fix uninit value in nsim_drv_configure_vfs()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Upstream commit(s):
commit 047304d0bfa5be2ace106974f87eec51e0832cd0
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Mon Nov 1 15:18:45 2021 -0700

    netdevsim: fix uninit value in nsim_drv_configure_vfs()

    Build bot points out that I missed initializing ret
    after refactoring.

    Reported-by: kernel test robot <lkp@intel.com>
    Fixes: 1c401078bcf3 ("netdevsim: move details of vf config to dev")
    Link: https://lore.kernel.org/r/20211101221845.3188490-1-kuba@kernel.org
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:58 +02:00
Petr Oros 7a47f72854 netdevsim: rename 'driver' entry points
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Conflicts:
- adjusted context conflict due to missing fc7a6209d57106 ("bus: Make
  remove callback return void")

Upstream commit(s):
commit a66f64b808150b5923dfad117d84ced3da2e6dfe
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Sat Oct 30 16:15:05 2021 -0700

    netdevsim: rename 'driver' entry points

    Rename functions serving as driver entry points
    from nsim_dev_... to nsim_drv_... this makes the
    API boundary between bus and dev clearer.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:58 +02:00
Petr Oros f11df89110 netdevsim: move max vf config to dev
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Upstream commit(s):
commit a3353ec3255437f59537f9478ea5cd7107ba1ebf
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Sat Oct 30 16:15:04 2021 -0700

    netdevsim: move max vf config to dev

    max_vfs is a strange little beast because the file
    hangs off of nsim's debugfs, but it configures a field
    in the bus device. Move it to dev.c, let's look at it
    as if the device driver was imposing VF limit based
    on FW info (like pci_sriov_set_totalvfs()).

    Again, when moving refactor the function not to hold
    the vfs lock pointlessly while parsing the input.
    Wrap the access from the read side in READ_ONCE()
    to appease concurrency checkers. Do not check if
    return value from snprintf() is negative...

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:58 +02:00
Petr Oros fb632bc872 netdevsim: move details of vf config to dev
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Upstream commit(s):
commit 1c401078bcf34e91e183b61b2d926972fc03b548
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Sat Oct 30 16:15:03 2021 -0700

    netdevsim: move details of vf config to dev

    Since "eswitch" configuration was added bus.c contains
    a lot of device details which really belong to dev.c.

    Restructure the code while moving it.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:58 +02:00
Petr Oros d0fd866953 netdevsim: move vfconfig to nsim_dev
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Conflicts:
- adjusted context conflict due to already applied 4c897cfc46a554
  ("devlink: Simplify devlink resources unregister call")

Upstream commit(s):
commit 5e388f3dc38c72da2880549e68374c3b6ba7c589
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Sat Oct 30 16:15:02 2021 -0700

    netdevsim: move vfconfig to nsim_dev

    When netdevsim got split into the faux bus vfconfig ended
    up in the bus device (think pci_dev) which is strange because
    it contains very networky not to say netdevy information.
    Move it to nsim_dev, which is the driver "priv" structure
    for the device.

    To make sure we don't race with probe/remove take
    the device lock (much like PCI).

    While at it remove the NULL-checking of vfconfigs.
    It appears to be pointless.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:58 +02:00
Petr Oros 298fc428fb netdevsim: remove max_vfs dentry
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2112332

Upstream commit(s):
commit ba064e4cf923326989a59da1e889f45282abb6b8
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Oct 28 14:17:53 2021 -0700

    netdevsim: remove max_vfs dentry

    Commit d395381909 ("netdevsim: Add max_vfs to bus_dev")
    added this file and saved the dentry for no apparent reason.

    Link: https://lore.kernel.org/r/20211028211753.22612-1-kuba@kernel.org
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-07-29 13:22:57 +02:00
Petr Oros a11917e851 devlink: Simplify devlink resources unregister call
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2073210

Conflicts:
- adjusted context conflicts due to missing 5e388f3dc38c72 ("netdevsim:
  move vfconfig to nsim_dev")

Upstream commit(s):
commit 4c897cfc46a554a523343fc3296333c473a2fc52
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue Nov 30 12:16:20 2021 +0200

    devlink: Simplify devlink resources unregister call

    The devlink_resources_unregister() used second parameter as an
    entry point for the recursive removal of devlink resources. None
    of the callers outside of devlink core needed to use this field,
    so let's remove it.

    As part of this removal, the "struct devlink_resource" was moved
    from .h to .c file as it is not possible to use in any place in
    the code except devlink.c.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-04-12 16:50:37 +02:00
Petr Oros d074428610 devlink: Delete reload enable/disable interface
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Conflicts:
-  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
   drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c
- Unmerged, because these files are not in RHEL

Upstream commit(s):
commit 82465bec3e9713c395b0a02f5aaf7949443cb877
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue Oct 12 16:15:26 2021 +0300

    devlink: Delete reload enable/disable interface

    Commit a0c76345e3 ("devlink: disallow reload operation during device
    cleanup") added devlink_reload_{enable,disable}() APIs to prevent reload
    operation from racing with device probe/dismantle.

    After recent changes to move devlink_register() to the end of device
    probe and devlink_unregister() to the beginning of device dismantle,
    these races can no longer happen. Reload operations will be denied if
    the devlink instance is unregistered and devlink_unregister() will block
    until all in-flight operations are done.

    Therefore, remove these devlink_reload_{enable,disable}() APIs.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:40 +01:00
Petr Oros 0931077d87 devlink: Allow control devlink ops behavior through feature mask
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Conflicts:
-  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
   drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c
- Unmerged, because these files are not in RHEL

Upstream commit(s):
commit bd032e35c568ff7cfa347aa4ddd6491e2453f00c
Author: Leon Romanovsky <leon@kernel.org>
Date:   Tue Oct 12 16:15:24 2021 +0300

    devlink: Allow control devlink ops behavior through feature mask

    Introduce new devlink call to set feature mask to control devlink
    behavior during device initialization phase after devlink_alloc()
    is already called.

    This allows us to set reload ops based on device property which
    is not known at the beginning of driver initialization.

    For the sake of simplicity, this API lacks any type of locking and
    needs to be called before devlink_register() to make sure that no
    parallel access to the ops is possible at this stage.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:40 +01:00
Petr Oros b3b1168505 netdevsim: Move devlink registration to be last devlink command
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Upstream commit(s):
commit 71c1b525934d5a50b404457d9eb7aa2c6d6b21a6
Author: Leon Romanovsky <leon@kernel.org>
Date:   Sat Sep 25 14:22:57 2021 +0300

    netdevsim: Move devlink registration to be last devlink command

    This change prevents from users to access device before devlink is
    fully configured.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:39 +01:00
Petr Oros d6b56447fe devlink: Make devlink_register to be void
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Conflicts:
-  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
   drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c
   drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
   drivers/net/wwan/iosm/iosm_ipc_devlink.c
- Unmerged paths because files missing in RHEL

Upstream commit(s):
commit db4278c55fa53760893266538e86e638330b03bb
Author: Leon Romanovsky <leon@kernel.org>
Date:   Wed Sep 22 11:58:03 2021 +0300

    devlink: Make devlink_register to be void

    devlink_register() can't fail and always returns success, but all drivers
    are obligated to check returned status anyway. This adds a lot of boilerplate
    code to handle impossible flow.

    Make devlink_register() void and simplify the drivers that use that
    API call.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Acked-by: Simon Horman <simon.horman@corigine.com>
    Acked-by: Vladimir Oltean <olteanv@gmail.com> # dsa
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:38 +01:00
Petr Oros d822450b69 devlink: Set device as early as possible
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Conflicts:
-  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
   drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c
- Unmerged paths because files missing in RHEL

Upstream commit(s):
commit 919d13a7e455c2e7676042d7a5f94c164e859d8a
Author: Leon Romanovsky <leon@kernel.org>
Date:   Sun Aug 8 21:57:43 2021 +0300

    devlink: Set device as early as possible

    All kernel devlink implementations call to devlink_alloc() during
    initialization routine for specific device which is used later as
    a parent device for devlink_register().

    Such late device assignment causes to the situation which requires us to
    call to device_register() before setting other parameters, but that call
    opens devlink to the world and makes accessible for the netlink users.

    Any attempt to move devlink_register() to be the last call generates the
    following error due to access to the devlink->dev pointer.

    [    8.758862]  devlink_nl_param_fill+0x2e8/0xe50
    [    8.760305]  devlink_param_notify+0x6d/0x180
    [    8.760435]  __devlink_params_register+0x2f1/0x670
    [    8.760558]  devlink_params_register+0x1e/0x20

    The simple change of API to set devlink device in the devlink_alloc()
    instead of devlink_register() fixes all this above and ensures that
    prior to call to devlink_register() everything already set.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:37 +01:00
Petr Oros d032ab5686 devlink: Allocate devlink directly in requested net namespace
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Upstream commit(s):
commit 26713455048eb19122b1561b471d30710177ef97
Author: Leon Romanovsky <leon@kernel.org>
Date:   Thu Jul 29 20:19:25 2021 +0300

    devlink: Allocate devlink directly in requested net namespace

    There is no need in extra call indirection and check from impossible
    flow where someone tries to set namespace without prior call
    to devlink_alloc().

    Instead of this extra logic and additional EXPORT_SYMBOL, use specialized
    devlink allocation function that receives net namespace as an argument.

    Such specialized API allows clear view when devlink initialized in wrong
    net namespace and/or kernel users don't try to change devlink namespace
    under the hood.

    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:37 +01:00
Petr Oros 4a267e20ea netdevsim: Protect both reload_down and reload_up paths
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Upstream commit(s):
commit 5c0418ed16109759c7aec86b72f9bf56a0358526
Author: Leon Romanovsky <leon@kernel.org>
Date:   Thu Aug 5 17:34:28 2021 +0300

    netdevsim: Protect both reload_down and reload_up paths

    Don't progress with adding and deleting ports as long as devlink
    reload is running.

    Fixes: 23809a726c0d ("netdevsim: Forbid devlink reload when adding or deleting ports")
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:37 +01:00
Petr Oros d707dd39c2 netdevsim: Forbid devlink reload when adding or deleting ports
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2032260

Upstream commit(s):
commit 23809a726c0d004b9d2474333181f8da07360469
Author: Leon Romanovsky <leon@kernel.org>
Date:   Thu Aug 5 14:02:45 2021 +0300

    netdevsim: Forbid devlink reload when adding or deleting ports

    In order to remove complexity in devlink core related to
    devlink_reload_enable/disable, let's rewrite new_port/del_port
    logic to rely on internal to netdevsim lcok.

    We should protect only reload_down flow because it destroys nsim_dev,
    which is needed for nsim_dev_port_add/nsim_dev_port_del to hold
    port_list_lock.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-01-15 09:31:37 +01:00
Oleksandr Mazur 275b51c27c drivers: net: netdevsim: fix devlink_trap selftests failing
devlink_trap tests for the netdevsim fail due to misspelled
debugfs file name. Change this name, as well as name of callback
function, to match the naming as in the devlink itself - 'trap_drop_counter'.

Test-results:
selftests: drivers/net/netdevsim: devlink_trap.sh
TEST: Initialization                                                [ OK ]
TEST: Trap action                                                   [ OK ]
TEST: Trap metadata                                                 [ OK ]
TEST: Non-existing trap                                             [ OK ]
TEST: Non-existing trap action                                      [ OK ]
TEST: Trap statistics                                               [ OK ]
TEST: Trap group action                                             [ OK ]
TEST: Non-existing trap group                                       [ OK ]
TEST: Trap group statistics                                         [ OK ]
TEST: Trap policer                                                  [ OK ]
TEST: Trap policer binding                                          [ OK ]
TEST: Port delete                                                   [ OK ]
TEST: Device delete                                                 [ OK ]

Fixes: a7b3527a43 ("drivers: net: netdevsim: add devlink trap_drop_counter_get implementation")
Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-18 11:28:27 -07:00
Oleksandr Mazur a7b3527a43 drivers: net: netdevsim: add devlink trap_drop_counter_get implementation
Whenever query statistics is issued for trap with DROP action,
devlink subsystem would also fill-in statistics 'dropped' field.
In case if device driver did't register callback for hard drop
statistics querying, 'dropped' field will be omitted and not filled.
Add trap_drop_counter_get callback implementation to the netdevsim.
Add new test cases for netdevsim, to test both the callback
functionality, as well as drop statistics alteration check.

Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-14 13:04:25 -07:00
Dan Carpenter 4e744cb812 netdevsim: delete unnecessary debugfs checking
In normal situations where the driver doesn't dereference
"nsim_node->ddir" or "nsim_node->rate_parent" itself then we are not
supposed to check the return from debugfs functions.  In the case of
debugfs_create_dir() the check was wrong as well because it doesn't
return NULL, it returns error pointers.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-09 14:16:39 -07:00
Dmytro Linkin f3d101b485 netdevsim: Allow setting parent node of rate objects
Implement new devlink ops that allow setting rate node as a parent for
devlink port (leaf) or another devlink node through devlink API.
Expose parent names to netdevsim debugfs in read only mode.

Co-developed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:37 -07:00
Dmytro Linkin 885226f568 netdevsim: Implement support for devlink rate nodes
Implement new devlink ops that allow creation, deletion and setting of
shared/max tx rate of devlink rate nodes through devlink API.
Expose rate node and it's tx rates to netdevsim debugfs.

Co-developed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:37 -07:00
Dmytro Linkin 605c4f8f19 netdevsim: Implement devlink rate leafs tx rate support
Implement new devlink ops that allow shared and max tx rate control for
devlink port rate objects (leafs) through devlink API.

Expose rate values of VF ports to netdevsim debugfs.

Co-developed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:37 -07:00
Dmytro Linkin 885dfe121b netdevsim: Register devlink rate leaf objects per VF
Register devlink rate leaf objects per VF.

Co-developed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Dmytro Linkin 160dc373ee netdevsim: Implement legacy/switchdev mode for VFs
Implement callbacks to set/get eswitch mode value. Add helpers to check
current mode.

Instantiate VFs' net devices and devlink ports on switchdev enabling and
remove them on legacy enabling. Changing number of VFs while in
switchdev mode triggers VFs creation/deletion.

Also disable NDO API callback to set VF rate, since it's legacy API.
Switchdev API to set VF rate will be implemented in one of the next
patches.

Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Dmytro Linkin 92ba1f29e6 netdevsim: Implement VFs
Allow creation of netdevsim ports for VFs along with allocations of
corresponding net devices and devlink ports.
Add enums and helpers to distinguish PFs' ports from VFs' ports.

Ports creation/deletion debugfs API intended to be used with physical
ports only.
VFs instantiation will be done in one of the next patches.

Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Dmytro Linkin 814b9ce65e netdevsim: Implement port types and indexing
Define type of ports, which netdevsim driver currently operates with as
PF. Define new port type - VF, which will be implemented in following
patches. Add helper functions to distinguish them. Add helper function
to get VF index from port index.

Add port indexing logic where PFs' indexes starts from 0, VFs' - from
NSIM_DEV_VF_PORT_INDEX_BASE.
All ports uses same index pool, which means that PF port may be created
with index from VFs' indexes range.
Maximum number of VFs, which the driver can allocate, is limited by
UINT_MAX - BASE.

Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Dmytro Linkin 32ac15d8fd netdevsim: Disable VFs on nsim_dev_reload_destroy() call
Move VFs disabling from device release() to nsim_dev_reload_destroy() to
make VFs disabling and ports removal simultaneous.
This is a requirement for VFs ports implemented in next patches.

Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Dmytro Linkin d395381909 netdevsim: Add max_vfs to bus_dev
Currently there is no limit to the number of VFs netdevsim can enable.
In a real systems this value exist and used by the driver.
Fore example, some features might need to consider this value when
allocating memory.

Expose max_vfs variable to debugfs as configurable resource. If are VFs
configured (num_vfs != 0) then changing of max_vfs not allowed.

Co-developed-by: Yuval Avnery <yuvalav@nvidia.com>
Signed-off-by: Yuval Avnery <yuvalav@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-02 14:08:36 -07:00
Ido Schimmel a8700c3dd0 netdevsim: Add dummy psample implementation
Allow netdevsim to report "sampled" packets to the psample module by
periodically generating packets from a work queue. The behavior can be
enabled / disabled (default) and the various meta data attributes can be
controlled via debugfs knobs.

This implementation enables both testing of the psample module with all
the optional attributes as well as development of user space
applications on top of psample such as hsflowd and a Wireshark dissector
for psample generic netlink packets.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-03-14 15:00:43 -07:00