From patchwork Thu Aug 25 08:04:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12954321 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C35FDC04AA5 for ; Thu, 25 Aug 2022 08:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239077AbiHYIEj (ORCPT ); Thu, 25 Aug 2022 04:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239176AbiHYIE3 (ORCPT ); Thu, 25 Aug 2022 04:04:29 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C4581B16 for ; Thu, 25 Aug 2022 01:04:24 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id z8so4429259edb.0 for ; Thu, 25 Aug 2022 01:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=qr1Znbfq6RYmCpWCpKuFbckFkpdkU947UID6SIUX69A=; b=ZYhYOhhIfO0TuE29zXcfDvI7l/SdVwiz/eHYi4eh/l/axj1j4o3R5hGwMp/6xntXgW tXYKOL1zaLz9NHS0RceHKnDEtHsXqPnkZI8S78sRgrHM0X56l8i2/SVl3wh0Hbsdu4zQ q8vLInZKZCH35ZIePD0YXD/u7k3ddfR77iZ2qA7cf0szwvvH1E+QKGghWmeBhve48Zvx w0oelBs8OC+8LvjUZHBRkDbd1V/d8FlRWz2nilZlW2szzFl46hMfi4Mx4kMx1VRH6KNb 4ZVsfOHDC+5liDZojxhQbMjC0xOpx6erTXjm8iZGp+ivs9J8h9sHrx7hOjJgUvfHxpCL aJOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=qr1Znbfq6RYmCpWCpKuFbckFkpdkU947UID6SIUX69A=; b=jtzJ3Ecm4ci9dF+/LM9qEzfrXXmZk6QMih4MaNuCj/+azaqZrd3Ue1c547wM6I14CF /Xl1u73GPC55DEqVSR1Dx5iCogUa+YOyY8JtCEQiNVDFfROzmtPSSBoOrH648dSEDPeG eXUA8Xfik2GOuFSxj/3YZQASnMKew0tVQJ/WVSxSXMdClxziSAZztOn8QBr4BWWsArBx t7KWkqpKjkXkdF86CV1D/klB+xwufPUIaS74gJ+M7jXSm7Vcuk1/TtvWE7co6WiXCYcX p3LlE64EqFqXt/llnYql/UfKwB4LfmMIpzbSoWzkX/xM7dguZr2hmyjgaKc/H+yi4NDK Q0fQ== X-Gm-Message-State: ACgBeo1n1bBxb3Dfa/Pi004qQZHIZdwcpn1zeXxi/yhlAitEP1iLOx77 w11XCZspafci+kNnfUEnHP+K3US8xfZODanV X-Google-Smtp-Source: AA6agR5zmp0BCIkQajyL000B6MhGqDC2lwwlS9U5NS5UZ2L43irWbqpZq3WklbrAWDl59mzLPFowow== X-Received: by 2002:a05:6402:514f:b0:445:e158:9eb7 with SMTP id n15-20020a056402514f00b00445e1589eb7mr2177283edd.322.1661414663418; Thu, 25 Aug 2022 01:04:23 -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 g18-20020a17090604d200b0073c80d008d5sm2051825eja.122.2022.08.25.01.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 01:04:22 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: sthemmin@microsoft.com, dsahern@gmail.com, vikas.gupta@broadcom.com, jacob.e.keller@intel.com, kuba@kernel.org, moshe@nvidia.com, saeedm@nvidia.com Subject: [patch iproute2-next 1/2] devlink: load port-ifname map on demand Date: Thu, 25 Aug 2022 10:04:19 +0200 Message-Id: <20220825080420.1282569-2-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220825080420.1282569-1-jiri@resnulli.us> References: <20220825080420.1282569-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko So far, the port-ifname map was loaded during devlink init no matter if actually needed or not. Port dump cmd which is utilized for this in kernel takes lock for every devlink instance. That may lead to unnecessary blockage of command. Load the map only in time it is needed to lookup ifname. Signed-off-by: Jiri Pirko --- devlink/devlink.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index b69c89778804..b2439aef4d10 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -374,6 +374,7 @@ struct dl { bool verbose; bool stats; bool hex; + bool map_loaded; struct { bool present; char *bus_name; @@ -817,13 +818,15 @@ static void ifname_map_fini(struct dl *dl) } } -static int ifname_map_init(struct dl *dl) +static void ifname_map_init(struct dl *dl) { - struct nlmsghdr *nlh; - int err; - INIT_LIST_HEAD(&dl->ifname_map_list); +} +static int ifname_map_load(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET, NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP); @@ -841,7 +844,16 @@ static int ifname_map_lookup(struct dl *dl, const char *ifname, uint32_t *p_port_index) { struct ifname_map *ifname_map; + int err; + if (!dl->map_loaded) { + err = ifname_map_load(dl); + if (err) { + pr_err("Failed to create index map\n"); + return err; + } + dl->map_loaded = true; + } list_for_each_entry(ifname_map, &dl->ifname_map_list, list) { if (strcmp(ifname, ifname_map->ifname) == 0) { *p_bus_name = ifname_map->bus_name; @@ -9622,17 +9634,10 @@ static int dl_init(struct dl *dl) return -errno; } - err = ifname_map_init(dl); - if (err) { - pr_err("Failed to create index map\n"); - goto err_ifname_map_create; - } + ifname_map_init(dl); + new_json_obj_plain(dl->json_output); return 0; - -err_ifname_map_create: - mnlu_gen_socket_close(&dl->nlg); - return err; } static void dl_fini(struct dl *dl) From patchwork Thu Aug 25 08:04:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12954323 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6431EC04AA5 for ; Thu, 25 Aug 2022 08:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239098AbiHYIEl (ORCPT ); Thu, 25 Aug 2022 04:04:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239195AbiHYIEa (ORCPT ); Thu, 25 Aug 2022 04:04:30 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 664DA564D5 for ; Thu, 25 Aug 2022 01:04:26 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id cu2so50775ejb.0 for ; Thu, 25 Aug 2022 01:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=srxGrVO76ra49mHxsKyT1OyGD8d3uD48+elNlBPQTyU=; b=Tvgn854lFD8CvFhPUY27B/D6iJqV68JRvIQ+idFUIhA3MBQZJxxSman3XD6W4S89zJ Rogj8go063VLJkURqcDwOFCzmxfC22pvfzW6qz4Z+RWUpFqgsrjTnTJOeEqt0Trq2V29 u+jExPKdwae4Eg+gZ1e53M9phozlpOPYhh/yiIkQrDNCw2HFuvdMY3/iIy7BEvRSUyKm 6ALRbxDMNO/IyAOem/JqgwBc6cGDOwrc8IKAkJES8X01YIb+ahk5D0++fYG6im1sz4Q2 z3cvG4ORJaUBrJlm1cRS9tqL+8tzEQJKT4dSTj766cSpQ8aSHCvBPu+tNMBCmA9Ovcfn SyeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=srxGrVO76ra49mHxsKyT1OyGD8d3uD48+elNlBPQTyU=; b=n0xXVgDR74X+GpINcY5ZtdmeZtD7Px7phcLS7Mdh2gGgny/ewZK/CptTYtCIQntCIq PdxHbQGRztQv5HnGnXaDURhGrRbPAH3n9+bNbLQAhiWgaRoXf6TJgYjAXdI+CoXnEope iuRj78H+t6C6TjwDa1nambh+LfNOWMgs2ISqg5VRsGvDQq52/Wy7X9qVvt4xZykyu9yA zOw9XDJe5O5DfY4dLciOA6tKYwcb3f21L2zWELQUstF8hjL8orXqRaLyyotyis0Jp7VP fjGYV8IM1Zq9cp5z9kzNYjvEgYsYHJQ7FyT+DIKdIzH5O5eUn6Pty+NJ+FC0H/FW0edL t1YQ== X-Gm-Message-State: ACgBeo21kBSzPGMM3lzOO/bgcEkvR1SZka3bS1FE9+YHMDJq/qGsMoWX jeAFoWPYjWo4XR453p90Ty4qd5LYAnRASbvp X-Google-Smtp-Source: AA6agR7V01PpkXVdx7UXuaN6cKd1xf0BXO+SwemZM/J1hlKdDMBuczp7p154gOC0FJCZZPLEXi2N6g== X-Received: by 2002:a17:907:2c67:b0:73d:c0fe:254b with SMTP id ib7-20020a1709072c6700b0073dc0fe254bmr1687078ejc.271.1661414664929; Thu, 25 Aug 2022 01:04:24 -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 bi1-20020a170906a24100b0073cc17cdb92sm2107433ejb.106.2022.08.25.01.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 01:04:24 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: sthemmin@microsoft.com, dsahern@gmail.com, vikas.gupta@broadcom.com, jacob.e.keller@intel.com, kuba@kernel.org, moshe@nvidia.com, saeedm@nvidia.com Subject: [patch iproute2-next 2/2] devlink: fix parallel flash notifications processing Date: Thu, 25 Aug 2022 10:04:20 +0200 Message-Id: <20220825080420.1282569-3-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220825080420.1282569-1-jiri@resnulli.us> References: <20220825080420.1282569-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Now that it is possible to flash multiple devlink instances in parallel, the notification processing callback needs to count in the fact that it receives message that belongs to different devlink instance. So handle the it gracefully and don't error out. Reported-by: Vikas Gupta Signed-off-by: Jiri Pirko --- devlink/devlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index b2439aef4d10..4f77e42f2d48 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3812,12 +3812,12 @@ static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data) mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME]) - return MNL_CB_ERROR; + return MNL_CB_STOP; bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]); dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]); if (strcmp(bus_name, opts->bus_name) || strcmp(dev_name, opts->dev_name)) - return MNL_CB_ERROR; + return MNL_CB_STOP; if (genl->cmd == DEVLINK_CMD_FLASH_UPDATE_END) { pr_out("\n");