mirror of
https://github.com/torvalds/linux
synced 2024-09-06 18:01:05 +00:00
![Jiri Pirko](/assets/img/avatar_default.png)
Recently, I've been hitting following deadlock warning during dpll pin
dump:
[52804.637962] ======================================================
[52804.638536] WARNING: possible circular locking dependency detected
[52804.639111] 6.8.0-rc2jiri+ #1 Not tainted
[52804.639529] ------------------------------------------------------
[52804.640104] python3/2984 is trying to acquire lock:
[52804.640581] ffff88810e642678 (nlk_cb_mutex-GENERIC){+.+.}-{3:3}, at: netlink_dump+0xb3/0x780
[52804.641417]
but task is already holding lock:
[52804.642010] ffffffff83bde4c8 (dpll_lock){+.+.}-{3:3}, at: dpll_lock_dumpit+0x13/0x20
[52804.642747]
which lock already depends on the new lock.
[52804.643551]
the existing dependency chain (in reverse order) is:
[52804.644259]
-> #1 (dpll_lock){+.+.}-{3:3}:
[52804.644836] lock_acquire+0x174/0x3e0
[52804.645271] __mutex_lock+0x119/0x1150
[52804.645723] dpll_lock_dumpit+0x13/0x20
[52804.646169] genl_start+0x266/0x320
[52804.646578] __netlink_dump_start+0x321/0x450
[52804.647056] genl_family_rcv_msg_dumpit+0x155/0x1e0
[52804.647575] genl_rcv_msg+0x1ed/0x3b0
[52804.648001] netlink_rcv_skb+0xdc/0x210
[52804.648440] genl_rcv+0x24/0x40
[52804.648831] netlink_unicast+0x2f1/0x490
[52804.649290] netlink_sendmsg+0x36d/0x660
[52804.649742] __sock_sendmsg+0x73/0xc0
[52804.650165] __sys_sendto+0x184/0x210
[52804.650597] __x64_sys_sendto+0x72/0x80
[52804.651045] do_syscall_64+0x6f/0x140
[52804.651474] entry_SYSCALL_64_after_hwframe+0x46/0x4e
[52804.652001]
-> #0 (nlk_cb_mutex-GENERIC){+.+.}-{3:3}:
[52804.652650] check_prev_add+0x1ae/0x1280
[52804.653107] __lock_acquire+0x1ed3/0x29a0
[52804.653559] lock_acquire+0x174/0x3e0
[52804.653984] __mutex_lock+0x119/0x1150
[52804.654423] netlink_dump+0xb3/0x780
[52804.654845] __netlink_dump_start+0x389/0x450
[52804.655321] genl_family_rcv_msg_dumpit+0x155/0x1e0
[52804.655842] genl_rcv_msg+0x1ed/0x3b0
[52804.656272] netlink_rcv_skb+0xdc/0x210
[52804.656721] genl_rcv+0x24/0x40
[52804.657119] netlink_unicast+0x2f1/0x490
[52804.657570] netlink_sendmsg+0x36d/0x660
[52804.658022] __sock_sendmsg+0x73/0xc0
[52804.658450] __sys_sendto+0x184/0x210
[52804.658877] __x64_sys_sendto+0x72/0x80
[52804.659322] do_syscall_64+0x6f/0x140
[52804.659752] entry_SYSCALL_64_after_hwframe+0x46/0x4e
[52804.660281]
other info that might help us debug this:
[52804.661077] Possible unsafe locking scenario:
[52804.661671] CPU0 CPU1
[52804.662129] ---- ----
[52804.662577] lock(dpll_lock);
[52804.662924] lock(nlk_cb_mutex-GENERIC);
[52804.663538] lock(dpll_lock);
[52804.664073] lock(nlk_cb_mutex-GENERIC);
[52804.664490]
The issue as follows: __netlink_dump_start() calls control->start(cb)
with nlk->cb_mutex held. In control->start(cb) the dpll_lock is taken.
Then nlk->cb_mutex is released and taken again in netlink_dump(), while
dpll_lock still being held. That leads to ABBA deadlock when another
CPU races with the same operation.
Fix this by moving dpll_lock taking into dumpit() callback which ensures
correct lock taking order.
Fixes: 9d71b54b65
("dpll: netlink: Add DPLL framework base functions")
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Link: https://lore.kernel.org/r/20240207115902.371649-1-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
161 lines
5 KiB
C
161 lines
5 KiB
C
// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
|
|
/* Do not edit directly, auto-generated from: */
|
|
/* Documentation/netlink/specs/dpll.yaml */
|
|
/* YNL-GEN kernel source */
|
|
|
|
#include <net/netlink.h>
|
|
#include <net/genetlink.h>
|
|
|
|
#include "dpll_nl.h"
|
|
|
|
#include <uapi/linux/dpll.h>
|
|
|
|
/* Common nested types */
|
|
const struct nla_policy dpll_pin_parent_device_nl_policy[DPLL_A_PIN_PHASE_OFFSET + 1] = {
|
|
[DPLL_A_PIN_PARENT_ID] = { .type = NLA_U32, },
|
|
[DPLL_A_PIN_DIRECTION] = NLA_POLICY_RANGE(NLA_U32, 1, 2),
|
|
[DPLL_A_PIN_PRIO] = { .type = NLA_U32, },
|
|
[DPLL_A_PIN_STATE] = NLA_POLICY_RANGE(NLA_U32, 1, 3),
|
|
[DPLL_A_PIN_PHASE_OFFSET] = { .type = NLA_S64, },
|
|
};
|
|
|
|
const struct nla_policy dpll_pin_parent_pin_nl_policy[DPLL_A_PIN_STATE + 1] = {
|
|
[DPLL_A_PIN_PARENT_ID] = { .type = NLA_U32, },
|
|
[DPLL_A_PIN_STATE] = NLA_POLICY_RANGE(NLA_U32, 1, 3),
|
|
};
|
|
|
|
/* DPLL_CMD_DEVICE_ID_GET - do */
|
|
static const struct nla_policy dpll_device_id_get_nl_policy[DPLL_A_TYPE + 1] = {
|
|
[DPLL_A_MODULE_NAME] = { .type = NLA_NUL_STRING, },
|
|
[DPLL_A_CLOCK_ID] = { .type = NLA_U64, },
|
|
[DPLL_A_TYPE] = NLA_POLICY_RANGE(NLA_U32, 1, 2),
|
|
};
|
|
|
|
/* DPLL_CMD_DEVICE_GET - do */
|
|
static const struct nla_policy dpll_device_get_nl_policy[DPLL_A_ID + 1] = {
|
|
[DPLL_A_ID] = { .type = NLA_U32, },
|
|
};
|
|
|
|
/* DPLL_CMD_DEVICE_SET - do */
|
|
static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_ID + 1] = {
|
|
[DPLL_A_ID] = { .type = NLA_U32, },
|
|
};
|
|
|
|
/* DPLL_CMD_PIN_ID_GET - do */
|
|
static const struct nla_policy dpll_pin_id_get_nl_policy[DPLL_A_PIN_TYPE + 1] = {
|
|
[DPLL_A_PIN_MODULE_NAME] = { .type = NLA_NUL_STRING, },
|
|
[DPLL_A_PIN_CLOCK_ID] = { .type = NLA_U64, },
|
|
[DPLL_A_PIN_BOARD_LABEL] = { .type = NLA_NUL_STRING, },
|
|
[DPLL_A_PIN_PANEL_LABEL] = { .type = NLA_NUL_STRING, },
|
|
[DPLL_A_PIN_PACKAGE_LABEL] = { .type = NLA_NUL_STRING, },
|
|
[DPLL_A_PIN_TYPE] = NLA_POLICY_RANGE(NLA_U32, 1, 5),
|
|
};
|
|
|
|
/* DPLL_CMD_PIN_GET - do */
|
|
static const struct nla_policy dpll_pin_get_do_nl_policy[DPLL_A_PIN_ID + 1] = {
|
|
[DPLL_A_PIN_ID] = { .type = NLA_U32, },
|
|
};
|
|
|
|
/* DPLL_CMD_PIN_GET - dump */
|
|
static const struct nla_policy dpll_pin_get_dump_nl_policy[DPLL_A_PIN_ID + 1] = {
|
|
[DPLL_A_PIN_ID] = { .type = NLA_U32, },
|
|
};
|
|
|
|
/* DPLL_CMD_PIN_SET - do */
|
|
static const struct nla_policy dpll_pin_set_nl_policy[DPLL_A_PIN_PHASE_ADJUST + 1] = {
|
|
[DPLL_A_PIN_ID] = { .type = NLA_U32, },
|
|
[DPLL_A_PIN_FREQUENCY] = { .type = NLA_U64, },
|
|
[DPLL_A_PIN_DIRECTION] = NLA_POLICY_RANGE(NLA_U32, 1, 2),
|
|
[DPLL_A_PIN_PRIO] = { .type = NLA_U32, },
|
|
[DPLL_A_PIN_STATE] = NLA_POLICY_RANGE(NLA_U32, 1, 3),
|
|
[DPLL_A_PIN_PARENT_DEVICE] = NLA_POLICY_NESTED(dpll_pin_parent_device_nl_policy),
|
|
[DPLL_A_PIN_PARENT_PIN] = NLA_POLICY_NESTED(dpll_pin_parent_pin_nl_policy),
|
|
[DPLL_A_PIN_PHASE_ADJUST] = { .type = NLA_S32, },
|
|
};
|
|
|
|
/* Ops table for dpll */
|
|
static const struct genl_split_ops dpll_nl_ops[] = {
|
|
{
|
|
.cmd = DPLL_CMD_DEVICE_ID_GET,
|
|
.pre_doit = dpll_lock_doit,
|
|
.doit = dpll_nl_device_id_get_doit,
|
|
.post_doit = dpll_unlock_doit,
|
|
.policy = dpll_device_id_get_nl_policy,
|
|
.maxattr = DPLL_A_TYPE,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_DEVICE_GET,
|
|
.pre_doit = dpll_pre_doit,
|
|
.doit = dpll_nl_device_get_doit,
|
|
.post_doit = dpll_post_doit,
|
|
.policy = dpll_device_get_nl_policy,
|
|
.maxattr = DPLL_A_ID,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_DEVICE_GET,
|
|
.dumpit = dpll_nl_device_get_dumpit,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_DEVICE_SET,
|
|
.pre_doit = dpll_pre_doit,
|
|
.doit = dpll_nl_device_set_doit,
|
|
.post_doit = dpll_post_doit,
|
|
.policy = dpll_device_set_nl_policy,
|
|
.maxattr = DPLL_A_ID,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_PIN_ID_GET,
|
|
.pre_doit = dpll_lock_doit,
|
|
.doit = dpll_nl_pin_id_get_doit,
|
|
.post_doit = dpll_unlock_doit,
|
|
.policy = dpll_pin_id_get_nl_policy,
|
|
.maxattr = DPLL_A_PIN_TYPE,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_PIN_GET,
|
|
.pre_doit = dpll_pin_pre_doit,
|
|
.doit = dpll_nl_pin_get_doit,
|
|
.post_doit = dpll_pin_post_doit,
|
|
.policy = dpll_pin_get_do_nl_policy,
|
|
.maxattr = DPLL_A_PIN_ID,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_PIN_GET,
|
|
.dumpit = dpll_nl_pin_get_dumpit,
|
|
.policy = dpll_pin_get_dump_nl_policy,
|
|
.maxattr = DPLL_A_PIN_ID,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
|
|
},
|
|
{
|
|
.cmd = DPLL_CMD_PIN_SET,
|
|
.pre_doit = dpll_pin_pre_doit,
|
|
.doit = dpll_nl_pin_set_doit,
|
|
.post_doit = dpll_pin_post_doit,
|
|
.policy = dpll_pin_set_nl_policy,
|
|
.maxattr = DPLL_A_PIN_PHASE_ADJUST,
|
|
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
|
|
},
|
|
};
|
|
|
|
static const struct genl_multicast_group dpll_nl_mcgrps[] = {
|
|
[DPLL_NLGRP_MONITOR] = { "monitor", },
|
|
};
|
|
|
|
struct genl_family dpll_nl_family __ro_after_init = {
|
|
.name = DPLL_FAMILY_NAME,
|
|
.version = DPLL_FAMILY_VERSION,
|
|
.netnsok = true,
|
|
.parallel_ops = true,
|
|
.module = THIS_MODULE,
|
|
.split_ops = dpll_nl_ops,
|
|
.n_split_ops = ARRAY_SIZE(dpll_nl_ops),
|
|
.mcgrps = dpll_nl_mcgrps,
|
|
.n_mcgrps = ARRAY_SIZE(dpll_nl_mcgrps),
|
|
};
|