mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 15:41:52 +02:00
Fix assert lock warning while calling devl_param_driverinit_value_set()
in ena.
WARNING: net/devlink/core.c:261 at devl_assert_locked+0x62/0x90, CPU#0: kworker/0:0/9
CPU: 0 UID: 0 PID: 9 Comm: kworker/0:0 Not tainted 6.19.0-rc2+ #1 PREEMPT(lazy)
Hardware name: Amazon EC2 m8i-flex.4xlarge/, BIOS 1.0 10/16/2017
Workqueue: events work_for_cpu_fn
RIP: 0010:devl_assert_locked+0x62/0x90
Call Trace:
<TASK>
devl_param_driverinit_value_set+0x15/0x1c0
ena_devlink_alloc+0x18c/0x220 [ena]
? __pfx_ena_devlink_alloc+0x10/0x10 [ena]
? trace_hardirqs_on+0x18/0x140
? lockdep_hardirqs_on+0x8c/0x130
? __raw_spin_unlock_irqrestore+0x5d/0x80
? __raw_spin_unlock_irqrestore+0x46/0x80
? devm_ioremap_wc+0x9a/0xd0
ena_probe+0x4d2/0x1b20 [ena]
? __lock_acquire+0x56a/0xbd0
? __pfx_ena_probe+0x10/0x10 [ena]
? local_clock+0x15/0x30
? __lock_release.isra.0+0x1c9/0x340
? mark_held_locks+0x40/0x70
? lockdep_hardirqs_on_prepare.part.0+0x92/0x170
? trace_hardirqs_on+0x18/0x140
? lockdep_hardirqs_on+0x8c/0x130
? __raw_spin_unlock_irqrestore+0x5d/0x80
? __raw_spin_unlock_irqrestore+0x46/0x80
? __pfx_ena_probe+0x10/0x10 [ena]
......
</TASK>
Fixes: 816b52624c ("net: ena: Control PHC enable through devlink")
Signed-off-by: Frank Liang <xiliang@redhat.com>
Reviewed-by: David Arinzon <darinzon@amazon.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://patch.msgid.link/20251231145808.6103-1-xiliang@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
215 lines
5.0 KiB
C
215 lines
5.0 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
|
/* Copyright (c) Amazon.com, Inc. or its affiliates.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include "linux/pci.h"
|
|
#include "ena_devlink.h"
|
|
#include "ena_phc.h"
|
|
|
|
static int ena_devlink_enable_phc_validate(struct devlink *devlink, u32 id,
|
|
union devlink_param_value val,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
|
|
if (!val.vbool)
|
|
return 0;
|
|
|
|
if (!ena_com_phc_supported(adapter->ena_dev)) {
|
|
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support PHC");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct devlink_param ena_devlink_params[] = {
|
|
DEVLINK_PARAM_GENERIC(ENABLE_PHC,
|
|
BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
|
|
NULL,
|
|
NULL,
|
|
ena_devlink_enable_phc_validate),
|
|
};
|
|
|
|
void ena_devlink_params_get(struct devlink *devlink)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
union devlink_param_value val;
|
|
int err;
|
|
|
|
err = devl_param_driverinit_value_get(devlink,
|
|
DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
|
|
&val);
|
|
if (err) {
|
|
netdev_err(adapter->netdev, "Failed to query PHC param\n");
|
|
return;
|
|
}
|
|
|
|
ena_phc_enable(adapter, val.vbool);
|
|
}
|
|
|
|
void ena_devlink_disable_phc_param(struct devlink *devlink)
|
|
{
|
|
union devlink_param_value value;
|
|
|
|
devl_lock(devlink);
|
|
value.vbool = false;
|
|
devl_param_driverinit_value_set(devlink,
|
|
DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
|
|
value);
|
|
devl_unlock(devlink);
|
|
}
|
|
|
|
static void ena_devlink_port_register(struct devlink *devlink)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
struct devlink_port_attrs attrs = {};
|
|
|
|
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
|
|
devlink_port_attrs_set(&adapter->devlink_port, &attrs);
|
|
devl_port_register(devlink, &adapter->devlink_port, 0);
|
|
}
|
|
|
|
static void ena_devlink_port_unregister(struct devlink *devlink)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
|
|
devl_port_unregister(&adapter->devlink_port);
|
|
}
|
|
|
|
static int ena_devlink_reload_down(struct devlink *devlink,
|
|
bool netns_change,
|
|
enum devlink_reload_action action,
|
|
enum devlink_reload_limit limit,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
|
|
if (netns_change) {
|
|
NL_SET_ERR_MSG_MOD(extack,
|
|
"Namespace change is not supported");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
ena_devlink_port_unregister(devlink);
|
|
|
|
rtnl_lock();
|
|
ena_destroy_device(adapter, false);
|
|
rtnl_unlock();
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ena_devlink_reload_up(struct devlink *devlink,
|
|
enum devlink_reload_action action,
|
|
enum devlink_reload_limit limit,
|
|
u32 *actions_performed,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
int err = 0;
|
|
|
|
rtnl_lock();
|
|
/* Check that no other routine initialized the device (e.g.
|
|
* ena_fw_reset_device()). Also we're under devlink_mutex here,
|
|
* so devlink isn't freed under our feet.
|
|
*/
|
|
if (!test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
|
|
err = ena_restore_device(adapter);
|
|
|
|
rtnl_unlock();
|
|
|
|
ena_devlink_port_register(devlink);
|
|
|
|
if (!err)
|
|
*actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT);
|
|
|
|
return err;
|
|
}
|
|
|
|
static const struct devlink_ops ena_devlink_ops = {
|
|
.reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT),
|
|
.reload_down = ena_devlink_reload_down,
|
|
.reload_up = ena_devlink_reload_up,
|
|
};
|
|
|
|
static int ena_devlink_configure_params(struct devlink *devlink)
|
|
{
|
|
struct ena_adapter *adapter = ENA_DEVLINK_PRIV(devlink);
|
|
union devlink_param_value value;
|
|
int rc;
|
|
|
|
rc = devlink_params_register(devlink, ena_devlink_params,
|
|
ARRAY_SIZE(ena_devlink_params));
|
|
if (rc) {
|
|
netdev_err(adapter->netdev, "Failed to register devlink params\n");
|
|
return rc;
|
|
}
|
|
|
|
devl_lock(devlink);
|
|
value.vbool = ena_phc_is_enabled(adapter);
|
|
devl_param_driverinit_value_set(devlink,
|
|
DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
|
|
value);
|
|
devl_unlock(devlink);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct devlink *ena_devlink_alloc(struct ena_adapter *adapter)
|
|
{
|
|
struct device *dev = &adapter->pdev->dev;
|
|
struct devlink *devlink;
|
|
|
|
devlink = devlink_alloc(&ena_devlink_ops,
|
|
sizeof(struct ena_adapter *),
|
|
dev);
|
|
if (!devlink) {
|
|
netdev_err(adapter->netdev,
|
|
"Failed to allocate devlink struct\n");
|
|
return NULL;
|
|
}
|
|
|
|
ENA_DEVLINK_PRIV(devlink) = adapter;
|
|
adapter->devlink = devlink;
|
|
|
|
if (ena_devlink_configure_params(devlink))
|
|
goto free_devlink;
|
|
|
|
return devlink;
|
|
|
|
free_devlink:
|
|
devlink_free(devlink);
|
|
return NULL;
|
|
}
|
|
|
|
static void ena_devlink_configure_params_clean(struct devlink *devlink)
|
|
{
|
|
devlink_params_unregister(devlink, ena_devlink_params,
|
|
ARRAY_SIZE(ena_devlink_params));
|
|
}
|
|
|
|
void ena_devlink_free(struct devlink *devlink)
|
|
{
|
|
ena_devlink_configure_params_clean(devlink);
|
|
|
|
devlink_free(devlink);
|
|
}
|
|
|
|
void ena_devlink_register(struct devlink *devlink, struct device *dev)
|
|
{
|
|
devl_lock(devlink);
|
|
ena_devlink_port_register(devlink);
|
|
devl_register(devlink);
|
|
devl_unlock(devlink);
|
|
}
|
|
|
|
void ena_devlink_unregister(struct devlink *devlink)
|
|
{
|
|
devl_lock(devlink);
|
|
ena_devlink_port_unregister(devlink);
|
|
devl_unregister(devlink);
|
|
devl_unlock(devlink);
|
|
}
|