From patchwork Fri Oct 13 12:10:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420834 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6C4114005 for ; Fri, 13 Oct 2023 12:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="ZOb4ytdo" Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A27BBF for ; Fri, 13 Oct 2023 05:10:35 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-307d58b3efbso1732918f8f.0 for ; Fri, 13 Oct 2023 05:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199033; x=1697803833; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n3LNEM/3RYbYoGteRoHDoFeUwZb7H2Soc5dB4GPyq1k=; b=ZOb4ytdowAuTJzhuqjFMKmiaPTCLOSb4VhR3PSJd8DDuuUxxf0PosiUcfO1xjfzFID ++qjhwVTiCgecvLEhOcaMlMkUbmPaAVFZbjX4X6C57scf/6qgPsSGH6J6jfeKRGEsz9R ctnyzopI5EByS8d1O1r6B8zSuTycMox/scZAqviIyo9puSBwN4d817JUXUO1DazoJHWd nneSRYxuydOEkDk2nlysRFfY5HoSq4ZwcrAAjgaU2IcxkzQGP2Q0m46UfOXuYUlTgykP BRqSaAp19nA7INkVxJ1JCLoXPGAXXRd/2G3Mo4IgQKBxMlfH8P/EXX282rxCuBrFP7W3 Skew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199033; x=1697803833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n3LNEM/3RYbYoGteRoHDoFeUwZb7H2Soc5dB4GPyq1k=; b=A0Lfrnw+7Mu8fuVVMgjETURX/0Yczm0J3slITxfcT6hYyID2njcnaOJAdULgb3Hke6 K5+ZRjI1CSRmiE0I/kWdgOs+a5Gm+8qoZchfmqDm+qDpU7uZK8unz2XbIY9Mw0islgO2 7i1tmsRxxAF4ZkhAgpdxqNWMRzRxA+HccfZRppLGV2j1aWqVSRQWUZPkvJwKiKX/PcvX IQHQx7wt39NA7+YGnnz1K6y7VjxuVtE+n4s+9DKkTtXV1HCvXSvjxgDjNKmG0DQS/P5p S84SL4rroSctM3yeAJcLy21+O9muo3CKlrdGsy0el82tU0RAL3q4KdPxjnZtHGFnqlxw 3uaw== X-Gm-Message-State: AOJu0Yy0nerQv8JsPNTxST8tHCsVntGScQB2/xrevWKQm4TaxvXHZZKf hsPkywqzj7yYCzw5pAo4GKAWgg24YBD9ReIKTIo= X-Google-Smtp-Source: AGHT+IGPX5UJmeqqviS9XPXOsJbLD+qhdF6XyoPay2/k5S6dy7WBXopwrdo9ksAMqTJjmSfJdb47Rw== X-Received: by 2002:adf:e383:0:b0:323:39d2:5803 with SMTP id e3-20020adfe383000000b0032339d25803mr23050167wrm.3.1697199033450; Fri, 13 Oct 2023 05:10:33 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id k7-20020adfb347000000b0032d8913f3dasm6502286wrd.97.2023.10.13.05.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:32 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 1/7] net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu() Date: Fri, 13 Oct 2023 14:10:23 +0200 Message-ID: <20231013121029.353351-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Make the net pointer stored in possible_net_t structure annotated as an RCU pointer. Change the access helpers to treat it as such. Introduce read_pnet_rcu() helper to allow caller to dereference the net pointer under RCU read lock. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v1->v2: - new patch --- include/net/net_namespace.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index eb6cd43b1746..13b3a4e29fdb 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -368,21 +368,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker) typedef struct { #ifdef CONFIG_NET_NS - struct net *net; + struct net __rcu *net; #endif } possible_net_t; static inline void write_pnet(possible_net_t *pnet, struct net *net) { #ifdef CONFIG_NET_NS - pnet->net = net; + rcu_assign_pointer(pnet->net, net); #endif } static inline struct net *read_pnet(const possible_net_t *pnet) { #ifdef CONFIG_NET_NS - return pnet->net; + return rcu_dereference_protected(pnet->net, true); +#else + return &init_net; +#endif +} + +static inline struct net *read_pnet_rcu(possible_net_t *pnet) +{ +#ifdef CONFIG_NET_NS + return rcu_dereference(pnet->net); #else return &init_net; #endif From patchwork Fri Oct 13 12:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420835 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5E7F14281 for ; Fri, 13 Oct 2023 12:10:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="14m3kXmg" Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B73C0 for ; Fri, 13 Oct 2023 05:10:37 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4060b623e64so13271195e9.0 for ; Fri, 13 Oct 2023 05:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199035; x=1697803835; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3BteKlWtczwBbbi14X3hBNkX3nvVNrL0AnYEmsEZz+A=; b=14m3kXmgIbIpNzubgIPmYhsCgqkAT9HN3Xcg8gKMInDbqSXVlnVTnR7Crrsq/6xdNA tVWe1HU/jqxo3yeqi2/tUNg5mGEEHzJMUtcZL/trpVJaJ/m9+BEg7R+Qv1T2dy8yYs3l TW64qYjkZXr8c5iyx+OX9fdkpmw25Awegvn4qV3RFHNEEibfak9vl+0HehKWqxLFniM4 1UvQatksu57xeHjMN6u8vm5UAno1s6OMiGYW1I3M9O2bn/891YxxIIghC1c2DaMSrN8X s/SiGQ08Hbzsl9UYQP5/qMxiblSw3l46bJ4V1Z2cBppnZviflb0TcDWphEOpLJhQhsNy UMmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199035; x=1697803835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3BteKlWtczwBbbi14X3hBNkX3nvVNrL0AnYEmsEZz+A=; b=S/uxstdiqc0VrjyYC8FLS9A4R98q1u1M8RrA+pv+Ocdk3730xHdazrzHHZQ1zt66lA 2ItBYWGoaxecAshG6T2y2C92sW/z+7A/IzyrBlN8XYtBIgteBCfAn5qwajztWm+4a4sV nl5cKVnD2/4x4MBhxXg2mbA9htaLOiZbToz3D1U7hVuvclJR0grmxDdc6z9YB6Q2ZDfa BXaolSO6QN5mFwKaEk7Dwqa44bJzHQdNjmDDlMAzaX+pRV/eKhyMk3qk4K3DLZqTQBOm 8yNlX93lqRAoHTmAyCS0DxO6p3QckFjZ8pzi9AwbWhcOxaDUrkuSnacE/0I80B5gYb+3 jiOA== X-Gm-Message-State: AOJu0Yyo5FFN7GJAzme41Jejj5iy4j+vTPocpo+UWTM+fRt8bopw0oW6 jMP+38iIsaa/Pw3qQCyq4TzFZedkZEfk+8rTIrw= X-Google-Smtp-Source: AGHT+IFRxfF8goVtrFGDSjask3+O/R0TaODjDOIgJ+e66thMh2TQ06GeXjpDVVvnlknZcpDIuEyb1Q== X-Received: by 2002:a7b:c457:0:b0:401:c8b9:4b86 with SMTP id l23-20020a7bc457000000b00401c8b94b86mr21696614wmi.9.1697199035307; Fri, 13 Oct 2023 05:10:35 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id g21-20020a7bc4d5000000b003fbe4cecc3bsm2336288wmk.16.2023.10.13.05.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:34 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 2/7] devlink: call peernet2id_alloc() with net pointer under RCU read lock Date: Fri, 13 Oct 2023 14:10:24 +0200 Message-ID: <20231013121029.353351-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko peernet2id_alloc() allows to be called lockless with peer net pointer obtained in RCU critical section and makes sure to return ns ID if net namespaces is not being removed concurrently. Benefit from read_pnet_rcu() helper addition, use it to obtain net pointer under RCU read lock and pass it to peernet2id_alloc() to get ns ID. Fixes: c137743bce02 ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - added fixes tag v1->v2: - moved the netns related bits from "devlink: don't take instance lock for nested handle put" - fixed the code using RCU to avoid use after free of peer net struct --- net/devlink/netlink.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 499304d9de49..809bfc3ba8c4 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -86,18 +86,24 @@ int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, struct devlink *devlink, int attrtype) { struct nlattr *nested_attr; + struct net *devl_net; nested_attr = nla_nest_start(msg, attrtype); if (!nested_attr) return -EMSGSIZE; if (devlink_nl_put_handle(msg, devlink)) goto nla_put_failure; - if (!net_eq(net, devlink_net(devlink))) { - int id = peernet2id_alloc(net, devlink_net(devlink), - GFP_KERNEL); + rcu_read_lock(); + devl_net = read_pnet_rcu(&devlink->_net); + if (!net_eq(net, devl_net)) { + int id = peernet2id_alloc(net, devl_net, GFP_ATOMIC); + + rcu_read_unlock(); if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id)) return -EMSGSIZE; + } else { + rcu_read_unlock(); } nla_nest_end(msg, nested_attr); From patchwork Fri Oct 13 12:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420836 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AB8514A8A for ; Fri, 13 Oct 2023 12:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="DvPAIB28" Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB54A9 for ; Fri, 13 Oct 2023 05:10:38 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40572aeb73cso21433045e9.3 for ; Fri, 13 Oct 2023 05:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199037; x=1697803837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fX3CFWk+KxItnDnCryM3nsfjHIR+y9KEaBmefgYyiZE=; b=DvPAIB28VIcneUPUJeI/0XWD/f1y9a32MgwhRybYMBDJ6xLeXNP8IcTnmeTSoWglad Pzfk4J6iixeu51Efsbl6WeGD7DBVs9twFmK6RAPfQrtioxqj1laxeiQkFM4ALrumI/v+ 4CRTUqBah5WweceJe2hR7vL7OBaDXI+2tfw8Ej/tRTl/3GxFBjdqLHWT9GJWDLE3ZwL5 u8OrOvhnfYSL9luOO67mDfp2M/PPiWEimUq8CrWTGAo55oeKw2nqTbAnFquH+X22xNTP KNkYq3mllsUQDuwyMJ9bPD4GPRDEm4eJ/VOIZx2+L/x+vPSE0zwUAR49O57rVBZJadar b2PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199037; x=1697803837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fX3CFWk+KxItnDnCryM3nsfjHIR+y9KEaBmefgYyiZE=; b=KrEY0V1UkbcE18zZ568BRNsDPkHsB/k9lWKqYcrJTNIulDKfIY/L4OK2VcHeHe4Kd0 AFFJ5dEkrof3kXFKx3Tw4ERn5nyE9TDrQPv+aKP66hqJVnx6iHMUl9PulSMzkQrctjX3 Xa0H9fH8hZ8g2LyFE+JEo94LIDC+cFV5QqHnDNiGQYHB3sGiEUsiWZu1NDb7hBC7W3WK Cwlmt6LgUQrpXKcECDORGITpKgCOD+0+aPT9FVXbXJILY3GpA+WEefMiFRW+pySuiUoY xN515QCBqfDt6m58HtN66rv5/sZA1AAPXzL4qNRRKD71g4QTEhtuktZjp4q2HwunNrha 3B2g== X-Gm-Message-State: AOJu0Ywlwkkaja39vpph7WvcSaGoWj6k/JrEjkRs2PQwGMkUYQR0MxIL L+55rYcRjB4fXRgDu8EthicEeRy3BAYJ2Z5I29I= X-Google-Smtp-Source: AGHT+IEZGzLjQVBxxCp2tA0FY4tCb+vYHpR0zI5Fow301vOCBJJvzwlXuLx8eA+wHF1EW1lvjv1rLw== X-Received: by 2002:a05:6000:118c:b0:32d:9787:53bc with SMTP id g12-20020a056000118c00b0032d978753bcmr2481862wrx.62.1697199036921; Fri, 13 Oct 2023 05:10:36 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id p13-20020a5d68cd000000b0031ae8d86af4sm20572360wrw.103.2023.10.13.05.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:36 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 3/7] devlink: take device reference for devlink object Date: Fri, 13 Oct 2023 14:10:25 +0200 Message-ID: <20231013121029.353351-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In preparation to allow to access device pointer without devlink instance lock held, make sure the device pointer is usable until devlink_release() is called. Fixes: c137743bce02 ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - moved the device reference related bits from "devlink: don't take instance lock for nested handle put" --- net/devlink/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index bcbbb952569f..c47c9e6c744f 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -310,6 +310,7 @@ static void devlink_release(struct work_struct *work) mutex_destroy(&devlink->lock); lockdep_unregister_key(&devlink->lock_key); + put_device(devlink->dev); kfree(devlink); } @@ -425,7 +426,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, if (ret < 0) goto err_xa_alloc; - devlink->dev = dev; + devlink->dev = get_device(dev); devlink->ops = ops; xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC); xa_init_flags(&devlink->params, XA_FLAGS_ALLOC); From patchwork Fri Oct 13 12:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420837 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6ABB15493 for ; Fri, 13 Oct 2023 12:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="irkWmS2N" Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0152BBE for ; Fri, 13 Oct 2023 05:10:39 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40566f89f6eso24129685e9.3 for ; Fri, 13 Oct 2023 05:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199038; x=1697803838; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2j6BiR1mkOIoFw5Np4OYyng//tCf04KW2VcDcYcacv4=; b=irkWmS2NyEF5b7qLmj2u8jWjrSx4bqMORlV+IDIe0rQdqDSwVvKgno+0M1tpFRj3iT bEgAca/Sa2QpGb0jAe2JHFsE5RIn+woW43faPBSyXmnEJgeOWj/WlGY4qI4U79KYU+we WA9a7DDIQVgDLAr9WdcrsOhKHWzt1i7JXeJSnIq6THCqKd/9O+RHpjGGnw3ZVlph5hsF ERck8C4JkVXTdGYg7qScVloNaijlvktben7RNNKf455NmoUIGyrit6X5bESdyrOXYvhl OpptFrMlOeubwTbdKuAiwaNieDOxaYtkwR5hvXsgU4gpkqhs4Jfsk1CCEythLC0p47j1 7uYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199038; x=1697803838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2j6BiR1mkOIoFw5Np4OYyng//tCf04KW2VcDcYcacv4=; b=hNhRJomYXHhDWUYTZuAb/lAAwO0eV+46ULEzpU7oQ3nHC2Y2kkeK1y2Nipg8RmEIm7 6K+G7ULuvmdrFcXdpxvx6XAdd0E9vhGidrdR2NHRkAQHAvX8W1yUHs5Ix+yKUBIdKKBn DuGeFBto8wJXl5Wh+FXkhq7WWxUe5bMz/3KACp8MQl0hmQv6PJNh9bEh5c3EZoLkZQMc HdDgPriAKt0+6BLvAnLk8iERIQV9JkRvAiGjUAqyMao5G2psshVln7Yc3XLQZOmIj7Sr Tr57QdY5aUlkcRly2XnezxWyXxdj0uFe/VH0x5Cx+aaHh/zCyWQ1v5MjAhvUe0ryE70R peDA== X-Gm-Message-State: AOJu0Ywh+aqzwbsn3GbaDZ+3ydTIVsAgZPLQCX4SZohTi7gt2wWh+42g YfeTGHJ5VXQFo1wX1ET8687TDbzWn09fSbSy5tM= X-Google-Smtp-Source: AGHT+IGYIZKBnBBeb/Qw0MR5ty0fk2W6VMsxjrr40nBdQq31jaW37p/M8KCAR+9vLye6cAl4rsInsg== X-Received: by 2002:a05:6000:1e91:b0:32d:83b7:bdb9 with SMTP id dd17-20020a0560001e9100b0032d83b7bdb9mr5982595wrb.21.1697199038451; Fri, 13 Oct 2023 05:10:38 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id j9-20020a5d4649000000b0031fb91f23e9sm20756844wrs.43.2023.10.13.05.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:37 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 4/7] devlink: don't take instance lock for nested handle put Date: Fri, 13 Oct 2023 14:10:26 +0200 Message-ID: <20231013121029.353351-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Lockdep reports following issue: WARNING: possible circular locking dependency detected ------------------------------------------------------ devlink/8191 is trying to acquire lock: ffff88813f32c250 (&devlink->lock_key#14){+.+.}-{3:3}, at: devlink_rel_devlink_handle_put+0x11e/0x2d0 but task is already holding lock: ffffffff8511eca8 (rtnl_mutex){+.+.}-{3:3}, at: unregister_netdev+0xe/0x20 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #3 (rtnl_mutex){+.+.}-{3:3}: lock_acquire+0x1c3/0x500 __mutex_lock+0x14c/0x1b20 register_netdevice_notifier_net+0x13/0x30 mlx5_lag_add_mdev+0x51c/0xa00 [mlx5_core] mlx5_load+0x222/0xc70 [mlx5_core] mlx5_init_one_devl_locked+0x4a0/0x1310 [mlx5_core] mlx5_init_one+0x3b/0x60 [mlx5_core] probe_one+0x786/0xd00 [mlx5_core] local_pci_probe+0xd7/0x180 pci_device_probe+0x231/0x720 really_probe+0x1e4/0xb60 __driver_probe_device+0x261/0x470 driver_probe_device+0x49/0x130 __driver_attach+0x215/0x4c0 bus_for_each_dev+0xf0/0x170 bus_add_driver+0x21d/0x590 driver_register+0x133/0x460 vdpa_match_remove+0x89/0xc0 [vdpa] do_one_initcall+0xc4/0x360 do_init_module+0x22d/0x760 load_module+0x51d7/0x6750 init_module_from_file+0xd2/0x130 idempotent_init_module+0x326/0x5a0 __x64_sys_finit_module+0xc1/0x130 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 -> #2 (mlx5_intf_mutex){+.+.}-{3:3}: lock_acquire+0x1c3/0x500 __mutex_lock+0x14c/0x1b20 mlx5_register_device+0x3e/0xd0 [mlx5_core] mlx5_init_one_devl_locked+0x8fa/0x1310 [mlx5_core] mlx5_devlink_reload_up+0x147/0x170 [mlx5_core] devlink_reload+0x203/0x380 devlink_nl_cmd_reload+0xb84/0x10e0 genl_family_rcv_msg_doit+0x1cc/0x2a0 genl_rcv_msg+0x3c9/0x670 netlink_rcv_skb+0x12c/0x360 genl_rcv+0x24/0x40 netlink_unicast+0x435/0x6f0 netlink_sendmsg+0x7a0/0xc70 sock_sendmsg+0xc5/0x190 __sys_sendto+0x1c8/0x290 __x64_sys_sendto+0xdc/0x1b0 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 -> #1 (&dev->lock_key#8){+.+.}-{3:3}: lock_acquire+0x1c3/0x500 __mutex_lock+0x14c/0x1b20 mlx5_init_one_devl_locked+0x45/0x1310 [mlx5_core] mlx5_devlink_reload_up+0x147/0x170 [mlx5_core] devlink_reload+0x203/0x380 devlink_nl_cmd_reload+0xb84/0x10e0 genl_family_rcv_msg_doit+0x1cc/0x2a0 genl_rcv_msg+0x3c9/0x670 netlink_rcv_skb+0x12c/0x360 genl_rcv+0x24/0x40 netlink_unicast+0x435/0x6f0 netlink_sendmsg+0x7a0/0xc70 sock_sendmsg+0xc5/0x190 __sys_sendto+0x1c8/0x290 __x64_sys_sendto+0xdc/0x1b0 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 -> #0 (&devlink->lock_key#14){+.+.}-{3:3}: check_prev_add+0x1af/0x2300 __lock_acquire+0x31d7/0x4eb0 lock_acquire+0x1c3/0x500 __mutex_lock+0x14c/0x1b20 devlink_rel_devlink_handle_put+0x11e/0x2d0 devlink_nl_port_fill+0xddf/0x1b00 devlink_port_notify+0xb5/0x220 __devlink_port_type_set+0x151/0x510 devlink_port_netdevice_event+0x17c/0x220 notifier_call_chain+0x97/0x240 unregister_netdevice_many_notify+0x876/0x1790 unregister_netdevice_queue+0x274/0x350 unregister_netdev+0x18/0x20 mlx5e_vport_rep_unload+0xc5/0x1c0 [mlx5_core] __esw_offloads_unload_rep+0xd8/0x130 [mlx5_core] mlx5_esw_offloads_rep_unload+0x52/0x70 [mlx5_core] mlx5_esw_offloads_unload_rep+0x85/0xc0 [mlx5_core] mlx5_eswitch_unload_sf_vport+0x41/0x90 [mlx5_core] mlx5_devlink_sf_port_del+0x120/0x280 [mlx5_core] genl_family_rcv_msg_doit+0x1cc/0x2a0 genl_rcv_msg+0x3c9/0x670 netlink_rcv_skb+0x12c/0x360 genl_rcv+0x24/0x40 netlink_unicast+0x435/0x6f0 netlink_sendmsg+0x7a0/0xc70 sock_sendmsg+0xc5/0x190 __sys_sendto+0x1c8/0x290 __x64_sys_sendto+0xdc/0x1b0 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 other info that might help us debug this: Chain exists of: &devlink->lock_key#14 --> mlx5_intf_mutex --> rtnl_mutex Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(rtnl_mutex); lock(mlx5_intf_mutex); lock(rtnl_mutex); lock(&devlink->lock_key#14); Problem is taking the devlink instance lock of nested instance when RTNL is already held. To fix this, don't take the devlink instance lock when putting nested handle. Instead, rely on the preparations done by previous two patches to be able to access device pointer and obtain netns id without devlink instance lock held. Fixes: c137743bce02 ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - push device reference part into separate patch - adjusted the patch description v1->v2: - push netns part into separate patch --- net/devlink/core.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index c47c9e6c744f..655903ddbdfd 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -183,9 +183,8 @@ static struct devlink_rel *devlink_rel_find(unsigned long rel_index) DEVLINK_REL_IN_USE); } -static struct devlink *devlink_rel_devlink_get_lock(u32 rel_index) +static struct devlink *devlink_rel_devlink_get(u32 rel_index) { - struct devlink *devlink; struct devlink_rel *rel; u32 devlink_index; @@ -198,16 +197,7 @@ static struct devlink *devlink_rel_devlink_get_lock(u32 rel_index) xa_unlock(&devlink_rels); if (!rel) return NULL; - devlink = devlinks_xa_get(devlink_index); - if (!devlink) - return NULL; - devl_lock(devlink); - if (!devl_is_registered(devlink)) { - devl_unlock(devlink); - devlink_put(devlink); - return NULL; - } - return devlink; + return devlinks_xa_get(devlink_index); } int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, @@ -218,11 +208,10 @@ int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, struct devlink *rel_devlink; int err; - rel_devlink = devlink_rel_devlink_get_lock(rel_index); + rel_devlink = devlink_rel_devlink_get(rel_index); if (!rel_devlink) return 0; err = devlink_nl_put_nested_handle(msg, net, rel_devlink, attrtype); - devl_unlock(rel_devlink); devlink_put(rel_devlink); if (!err && msg_updated) *msg_updated = true; From patchwork Fri Oct 13 12:10:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420838 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2539815E85 for ; Fri, 13 Oct 2023 12:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="wMUTTtCi" Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4B68BF for ; Fri, 13 Oct 2023 05:10:41 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4065dea9a33so20803365e9.3 for ; Fri, 13 Oct 2023 05:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199040; x=1697803840; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JH6Db1nTJ41ItQd67j8/vw2ujOmqrcYuZLY5GzdIGUY=; b=wMUTTtCi/r/7b9O/cjhuyfFGZTAeykcScI7wGdkSz3HboPcOg2nFZIGlYtAB/cZGMC /cY1qZv7xF1toQAiGK9t/C0hugt2DUwvKAEGqzlpEbUKn7me37HvYdOfP4o+kDuUjQ8d Qod3A8giDmZu5eEZUFFKdc5hF3EleDE6EhfdXWORp0F8B3M04N1PU1DCTWx0f484xENN Iexr30urWAflSO/7yUZ1xQYU9RJD6rRdxaYYYerjRtUP5AAQCcSqA4a8eJkxaFgecxbx UzTRZAkatd7+B5IikyT7bPGobSKOYh1QGxlUa6dwD5MwUgu7mBDCVY7YHfaER6MFFK+B DGAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199040; x=1697803840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JH6Db1nTJ41ItQd67j8/vw2ujOmqrcYuZLY5GzdIGUY=; b=LTvJcfTm00hdbgZR5a5blbyoFJv+XIgf9JPhcIiFnkI3WnnIYFcDq3J8l/Tx7zstyw yzRtYAZe6vN0T0R/e8SlrXp4poN9N9XbmfXliGOlSpO29F0BPXISIllY2DewCcsIbhfA RR393KnZy4iazS4EfiaxZMbjAoKOA1ZFIL5YD0JCtWKD7+lJrJudTuMAO6usX6HADsBQ rBBuAcuZmz0aK/Kbv6qw4oSzpUgZVw2xcxtqdd1epX596lk1OaD0+ONE+o6e9odseFrU gnHEXOyy2e5/ee0aA4icM0hnS6QhsDCqT194S6zJr4Y3PJe09k9dNikw0t5WUmtI/EZn fL7Q== X-Gm-Message-State: AOJu0Yz7HcUJgrV7MK4n4FrDEONpodwHCBUKicD7JPtRwTQa7zhffG+1 so7Rji2LDhPCv/or8f+q4QLcB6yds9R566//Okw= X-Google-Smtp-Source: AGHT+IEAh413Wf/KR7aYVAOtCpGOq74KFZOF8x4Hlzy5M1EZHPVcMOw0837gz7xkbDrD9BF/rWtE3g== X-Received: by 2002:a05:600c:ac7:b0:403:b6bc:d90d with SMTP id c7-20020a05600c0ac700b00403b6bcd90dmr23844861wmr.20.1697199040310; Fri, 13 Oct 2023 05:10:40 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id n8-20020a7bcbc8000000b00405c7591b09sm2394698wmi.35.2023.10.13.05.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:39 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 5/7] Documentation: devlink: add nested instance section Date: Fri, 13 Oct 2023 14:10:27 +0200 Message-ID: <20231013121029.353351-6-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Add a part talking about nested devlink instances describing the helpers and locking ordering. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - new patch --- Documentation/networking/devlink/index.rst | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index b49749e2b9a6..52e52a1b603d 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -18,6 +18,30 @@ netlink commands. Drivers are encouraged to use the devlink instance lock for their own needs. +Nested instances +---------------- + +Some objects, like linecards or port functions, could have another +devlink instances created underneath. In that case, drivers should make +sure to respect following rules: + + - Lock ordering should be maintained. If driver needs to take instance + lock of both nested and parent instances at the same time, devlink + instance lock of the parent instance should be taken first, only then + instance lock of the nested instance could be taken. + - Driver should use object-specific helpers to setup the + nested relationship: + + - ``devl_nested_devlink_set()`` - called to setup devlink -> nested + devlink relationship (could be user for multiple nested instances. + - ``devl_port_fn_devlink_set()`` - called to setup port function -> + nested devlink relationship. + - ``devlink_linecard_nested_dl_set()`` - called to setup linecard -> + nested devlink relationship. + +The nested devlink info is exposed to the userspace over object-specific +attributes of devlink netlink. + Interface documentation ----------------------- From patchwork Fri Oct 13 12:10:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420839 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FF0915E94 for ; Fri, 13 Oct 2023 12:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="VPIi5OzO" Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AD63A9 for ; Fri, 13 Oct 2023 05:10:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3296b3f03e5so1812934f8f.2 for ; Fri, 13 Oct 2023 05:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199042; x=1697803842; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UKelGZo5ZvUTtY9mTp2kwHMa1UEMD5quN0mc49nRyJ8=; b=VPIi5OzOHCuePJmyE4ogusuXmomRecn3UQHEyWBU8h+3MzvxujjrjnPhpSmaFuaKJh rRY0xtmJj+yU49h2Jtt/DLZfcOZ0Q5aJcFDbsy0Kwy6+hRLoZBEsO0kzmhLjDv8CPa02 IGRe1x21KP8W24SV/5PzyuD1CZ5czoaYKGztsdqQb+GP9XKeoyteW++qYAJjvfUDqL3B FpjSB4HYdSBYfRvaBBUDdn+X51DaZuN9JbWrXZsBMoBv4tjG0d2P1Q/8R/lxXJHVIoVQ GbCZG7lmU1L8cVP+o/e943AXaOaD84RlQyE7yR2fTypXBUkx6rEqYn+ISNMhwvNLUti9 DTGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199042; x=1697803842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UKelGZo5ZvUTtY9mTp2kwHMa1UEMD5quN0mc49nRyJ8=; b=afGzt+HeRl+nuEN4YPIT2uFYbZke06I0l7/lbD2xZ4p0ZurTDi43DV2qgYDOjL9POZ O+3pqG/GLTwP3wUz1LIW1ImabaK7w13laeqxd/TuGSc1fBoeFMzxq5T+dEOXRJnlBN2J jMoa4WMc9f50MVLEqmYzx2eeC6CKjsS1lwq7xAa34m8Lz+jI5er5UKtF7IwwMUy58C6S 4doTY3R5fePeGvSo7cGxGfUpbrkRqUaOmRXbxIcrC1dO/P0zIZ1ipyP79ESCNQKVQexy JUMGcogGTqp053QJZD/LjzX/ItmSpkzr7e+jIKaSd24pxCnjAT82bk24XDb+T7PURNZB OqWQ== X-Gm-Message-State: AOJu0Yx2L1RkWtO6m4B858e9zUakOQ0Shv7h7V7LRVh04cq1uHF7wTWp k+exax8usWWenOcsdCJP3+dTY0cBubFeH25Mtq4= X-Google-Smtp-Source: AGHT+IEYDfCljcpgNJME/JRd4YepC03f2PxHM2OtlvjE1kPACgmdOerU8S84GFsUUK1ZASJZv+8eZA== X-Received: by 2002:a5d:4fd1:0:b0:32d:9a2b:4f83 with SMTP id h17-20020a5d4fd1000000b0032d9a2b4f83mr1471651wrw.33.1697199041838; Fri, 13 Oct 2023 05:10:41 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b003232d122dbfsm20863076wrm.66.2023.10.13.05.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:41 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 6/7] Documentation: devlink: add a note about RTNL lock into locking section Date: Fri, 13 Oct 2023 14:10:28 +0200 Message-ID: <20231013121029.353351-7-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Add a note describing the locking order of taking RTNL lock with devlink instance lock. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - new patch --- Documentation/networking/devlink/index.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index 52e52a1b603d..2884ad243b54 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -18,6 +18,10 @@ netlink commands. Drivers are encouraged to use the devlink instance lock for their own needs. +Drivers need to be cautious when taking devlink instance lock and +taking RTNL lock at the same time. Devlink instance lock needs to be taken +first, only after that RTNL lock could be taken. + Nested instances ---------------- From patchwork Fri Oct 13 12:10:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13420840 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 412CA15EB4 for ; Fri, 13 Oct 2023 12:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="tDZPaNpT" Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8260BE for ; Fri, 13 Oct 2023 05:10:44 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4054f790190so23311925e9.2 for ; Fri, 13 Oct 2023 05:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1697199043; x=1697803843; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oXSuLugNfkeM0OlmIJX1tWHroCO72P+V4QE7EVi+a2E=; b=tDZPaNpTbvUZb+8xBgXOkjd7yDqQ2sBOqyzj7KPv/4Pm3hTryCjgM3RMZ+Y9qtoycl qf5LY7dokAj7e4FZX47vkk3K5H1J5rCvfykGaKkvcXWREqB4vKCusCDy+9y0b1/RCSMc J6oqIBNTbO57yhaMa2kNCKjQagd1pOIV4jWzpwazvGWbdclT4zLDWAy+9qFbQKkiT7pn 5sdroKMDjaSwWaURl7YOqW04oxen+Z6gVhUkUHFaSI9qaF9TWQun86LETsktTdoMRHnZ TZIv0JX6vZsTzwspZS+psasCDOuSwBjDNo8b8ivKXTgq/v56CZV9Y/4Ex+OU8uaPSXxS K6WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199043; x=1697803843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oXSuLugNfkeM0OlmIJX1tWHroCO72P+V4QE7EVi+a2E=; b=PrHRuBxW1inkt0CvOD5AaORPBo4AVGp0pac3eUgNRHDAnKQ965DxLy4Zi9Me5RuM2+ p4xw6suWMe1PI+cXQW/72wauYU8aAQuPLzpUTD4DowvXxdm31UqRPog8dIPkEkACGIww vWBttDY6VLuU2KpAztdRZ4XEx/5SSfHHLzq64Om+vWZg5J4lXPgteou2ZTlus+TwrQnf 2E2k0zMAB22uVYjndYOeKmNcz/3GkLxwRUBtPDYixyCm6X6kIawMLzRZom+XO7FmJtfo HvyDYyP271l5QqF69GcGt9DLdNSC1+AbI86VUnjHxVabju7fQeSZCJaaIx1ymHXcQU2n EUzg== X-Gm-Message-State: AOJu0YwpVge+4tIXy0qD4qQimBl1Gfr+1w4Kt3GiSk2jiZMRjnmcUZUI dCwXlaX8tvnD4xaHulzl8RVbDx7n8r/0+7WL6sI= X-Google-Smtp-Source: AGHT+IEeda9rrgeXXOzXP13TbNgNFq/sydyNmXcPrjgy8JUZnNOY1SaIKc/+Txgg8FbLdTxBruH44Q== X-Received: by 2002:a7b:ca57:0:b0:405:34e4:14cf with SMTP id m23-20020a7bca57000000b0040534e414cfmr24086982wml.4.1697199043329; Fri, 13 Oct 2023 05:10:43 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id p19-20020a05600c469300b00407752f5ab6sm1100441wmo.6.2023.10.13.05.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:10:42 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com Subject: [patch net-next v3 7/7] devlink: document devlink_rel_nested_in_notify() function Date: Fri, 13 Oct 2023 14:10:29 +0200 Message-ID: <20231013121029.353351-8-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013121029.353351-1-jiri@resnulli.us> References: <20231013121029.353351-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Add a documentation for devlink_rel_nested_in_notify() describing the devlink instance locking consequences. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- v2->v3: - new patch --- net/devlink/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/devlink/core.c b/net/devlink/core.c index 655903ddbdfd..6984877e9f10 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -168,6 +168,20 @@ int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index, return 0; } +/** + * devlink_rel_nested_in_notify - Notify the object this devlink + * instance is nested in. + * @devlink: devlink + * + * This is called upon network namespace change of devlink instance. + * In case this devlink instance is nested in another devlink object, + * a notification of a change of this object should be sent + * over netlink. The parent devlink instance lock needs to be + * taken during the notification preparation. + * However, since the devlink lock of nested instance is held here, + * we would end with wrong devlink instance lock ordering and + * deadlock. Therefore the work is utilized to avoid that. + */ void devlink_rel_nested_in_notify(struct devlink *devlink) { struct devlink_rel *rel = devlink->rel;