From patchwork Wed Sep 13 07:12:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382523 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 3F4C618049 for ; Wed, 13 Sep 2023 07:12:50 +0000 (UTC) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381801728 for ; Wed, 13 Sep 2023 00:12:49 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31f915c3c42so3944969f8f.0 for ; Wed, 13 Sep 2023 00:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589167; x=1695193967; 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=QN8q4XBfm3D9pTOrAcZXoCrCq4gI7qNgVO87RHtcd8Y=; b=ag4Ss4nfYiKDqTR3bpfZz0Ae/1Yu3/C6Nbz/jR7r2SVwoAUn/tZ4naEiEz/TfKur6B +04EcaELG5nuDcvGd1RZqvghtg9pKQ0yiC/HuOMjFRB1GfOnZIOHsQtnRBHWcq6PnVmm YBK7PTUE502Xgrqt7TJE6JO+EyZ2/cUIOxd7sOmleMwBt6d0VdVy6kXsUFLNyomXBm4l bZmVuJDAt9SygdRMhEj1V+NDZDMLeH9mcKwU8J2Y2IqOVb+HMqMInoHh7wMkaEU2B3fz XNlWEQiKHQroxEL+RaFYJO6ZNbS+FSpFDSaKDds9uVXcgGyKfWeEHi9/2Szj65799oLZ zwLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589167; x=1695193967; 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=QN8q4XBfm3D9pTOrAcZXoCrCq4gI7qNgVO87RHtcd8Y=; b=xI+OrAX0lHu9EFHc7VgLHFLvakhtFPbeouatH7Gm+aQk/uKuQ0VyfqbyZ9sMulIZ6e pwTLZAgSJZHB7fCvjgnNCEIo5XMVNpXYzWgDl1EfU82rTcWQQIrYLMNjOk1UbSlQ2JAo 2nZdq72qqjKIfARLjPfV3SKeE2Vh/An9w49q9owFF8nRwIPae6JGWd5E5Bwee20rnvdF 5OeiKiNjFcZAmOcnncJMTcXRULD/RQ/1mm7+AeEoSD5TyctxGqb5npy3RYjbi1LbuTgw 6LQ6XeclaXBibs5+55g42FR2jXuf5VwNBQUavFmcKYsRQbLBhJxdnjDbVUqWo4LqJi2M s1mg== X-Gm-Message-State: AOJu0Yy6UAY/0CkXm8RncxBJW9R1AHToDTvHQ8nTzb617OCehMkRoLHK TqXF+5+LLR0/vTz0L7t40X/ByhKzQsRJQDlFENo= X-Google-Smtp-Source: AGHT+IHhK/o9tMnGq9BysiNRfyMeq9z/6sa64HJj0CuN3iVrpsaxCiUlL5hQVBqpNBLVSwMIGJ2+Ww== X-Received: by 2002:a5d:55c1:0:b0:31d:d3db:4566 with SMTP id i1-20020a5d55c1000000b0031dd3db4566mr1381572wrw.4.1694589167762; Wed, 13 Sep 2023 00:12:47 -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 n6-20020adfe786000000b003197efd1e7bsm14600739wrm.114.2023.09.13.00.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:47 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 01/12] devlink: move linecard struct into linecard.c Date: Wed, 13 Sep 2023 09:12:32 +0200 Message-ID: <20230913071243.930265-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Instead of exposing linecard struct, expose a simple helper to get the linecard index, which is all is needed outside linecard.c. Move the linecard struct to linecard.c and keep it private similar to the rest of the devlink objects. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- net/devlink/devl_internal.h | 14 +------------- net/devlink/linecard.c | 19 +++++++++++++++++++ net/devlink/port.c | 4 ++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index f6b5fea2e13c..1b05c2c09e27 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -206,19 +206,7 @@ int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, struct netlink_ext_ack *extack); /* Linecards */ -struct devlink_linecard { - struct list_head list; - struct devlink *devlink; - unsigned int index; - const struct devlink_linecard_ops *ops; - void *priv; - enum devlink_linecard_state state; - struct mutex state_lock; /* Protects state */ - const char *type; - struct devlink_linecard_type *types; - unsigned int types_count; - struct devlink *nested_devlink; -}; +unsigned int devlink_linecard_index(struct devlink_linecard *linecard); /* Devlink nl cmds */ int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info); diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c index 85c32c314b0f..a0210ba56f2d 100644 --- a/net/devlink/linecard.c +++ b/net/devlink/linecard.c @@ -6,6 +6,25 @@ #include "devl_internal.h" +struct devlink_linecard { + struct list_head list; + struct devlink *devlink; + unsigned int index; + const struct devlink_linecard_ops *ops; + void *priv; + enum devlink_linecard_state state; + struct mutex state_lock; /* Protects state */ + const char *type; + struct devlink_linecard_type *types; + unsigned int types_count; + struct devlink *nested_devlink; +}; + +unsigned int devlink_linecard_index(struct devlink_linecard *linecard) +{ + return linecard->index; +} + static struct devlink_linecard * devlink_linecard_get_by_index(struct devlink *devlink, unsigned int linecard_index) diff --git a/net/devlink/port.c b/net/devlink/port.c index 4763b42885fb..7b300a322ed9 100644 --- a/net/devlink/port.c +++ b/net/devlink/port.c @@ -483,7 +483,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, goto nla_put_failure; if (devlink_port->linecard && nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, - devlink_port->linecard->index)) + devlink_linecard_index(devlink_port->linecard))) goto nla_put_failure; genlmsg_end(msg, hdr); @@ -1420,7 +1420,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, case DEVLINK_PORT_FLAVOUR_PHYSICAL: if (devlink_port->linecard) n = snprintf(name, len, "l%u", - devlink_port->linecard->index); + devlink_linecard_index(devlink_port->linecard)); if (n < len) n += snprintf(name + n, len - n, "p%u", attrs->phys.port_number); From patchwork Wed Sep 13 07:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382524 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 D9514182A4 for ; Wed, 13 Sep 2023 07:12:51 +0000 (UTC) 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 167591729 for ; Wed, 13 Sep 2023 00:12:51 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-401da71b7faso75329355e9.2 for ; Wed, 13 Sep 2023 00:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589169; x=1695193969; 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=ndFgl5rQ+eLb/RGVgEXExn24nZ5LgTHyOKGUMhNNXIc=; b=vD1RB/7JP2PAyya9bhZyoCTRSHD/2B9Z2gfTu1hpEHi+vqu16IFhItYAttHzTZBS0X MSq4LgEdGAqwqUV3e3d9esMHAfXKEUsJI2d7oiIyN5z2AGOQECyOZKieRxb/ycyJxmoO aoSKC+WmlhAXsYEEkazbpKjjutJbWC/QfkC2xzosK1kgSIA4K0JF3N+pNBMC0rj3stpo OnnZvhwER62QRnveHU3INiXRrpESOD9lUkk+HeOQJhfirGm5uAuA1ItYAO2M1LBKPCAY rTJv85Q+J1cNUAJBphBU3K6NG7Zuta8BpYxyk0TzkzHd2IqwmVNUr3kJbC9S5RU4jx0m Taqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589169; x=1695193969; 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=ndFgl5rQ+eLb/RGVgEXExn24nZ5LgTHyOKGUMhNNXIc=; b=vayPTKVZ15YkvVq6ukQ7/HOcdAKAEbzOmHCvv2cbSI98ajU/4Xj4IFsKIgsjY4QE74 v/htZ9JZYWWXgYpWJkIu+fpsGyJfAoBbsR05BzGTLGioK0lvUKs826bUDvcxarVE97W6 mm3U5PbgA1GfapFa9KWitxT45ThOWPGGd2UFCGCiFBZR3uMJhqEfpVERHdCYO4ic4DaR fEVVYtIE7yYGGwG7hAf14C96F7jeNB6L73uVVeiLB0JmBespHFc+xm8ipNjPpoTf0GDu l2g/2y22Cb6ubrc+8RY3y19prHq/+jKFhMTqsI65SyG3sAnLNv3Kk6xJHrQgZ1d4z3ca wX3A== X-Gm-Message-State: AOJu0YwZolvCo1W4J3LLpVFAzg4THcOtHytk7FzlqrdZekOOP87aFpkK hQh1zsQxsDvu+U2QARzKrgCJrvNA8m5fwG+H9C8= X-Google-Smtp-Source: AGHT+IGIMa3qf4yeZgKgvKNUEyiJxQLifeqs4WfDPPzkVL5/gO7noP/6BCEZSAbPteZ2mUL3y2rqRA== X-Received: by 2002:a05:6000:1190:b0:317:f046:25ef with SMTP id g16-20020a056000119000b00317f04625efmr1432596wrx.44.1694589169467; Wed, 13 Sep 2023 00:12:49 -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 t3-20020a05600001c300b0031f07d1edbcsm14776978wrx.77.2023.09.13.00.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:48 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload() Date: Wed, 13 Sep 2023 09:12:33 +0200 Message-ID: <20230913071243.930265-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The eswitch disable call does removal of all representors. Do that before clearing the SF device table and maintain the same flow as during SF devlink port removal, where the representor is removed before the actual SF is removed. Signed-off-by: Jiri Pirko --- v1->v2: - fixed a typo in patch description --- drivers/net/ethernet/mellanox/mlx5/core/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 15561965d2af..d17c9c31b165 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1405,9 +1405,9 @@ static int mlx5_load(struct mlx5_core_dev *dev) static void mlx5_unload(struct mlx5_core_dev *dev) { + mlx5_eswitch_disable(dev->priv.eswitch); mlx5_devlink_traps_unregister(priv_to_devlink(dev)); mlx5_sf_dev_table_destroy(dev); - mlx5_eswitch_disable(dev->priv.eswitch); mlx5_sriov_detach(dev); mlx5_lag_remove_mdev(dev); mlx5_ec_cleanup(dev); From patchwork Wed Sep 13 07:12:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382525 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 584C5182A4 for ; Wed, 13 Sep 2023 07:12:53 +0000 (UTC) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763771728 for ; Wed, 13 Sep 2023 00:12:52 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-401d67434daso70008715e9.2 for ; Wed, 13 Sep 2023 00:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589171; x=1695193971; 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=tx5cwCcgwsE/VDoxUQV5N86Hk7Oe81f9AvXImzVF+5A=; b=m5ggpqFT8fUJaCSGSD1tm3MIy1IB1TooSxNlSbMlqIn/3KeVPP4M18fQunKcoINc5p OLib6ZoKreuWG1n54Y23HmdUlaRm9/XToJ9ZRJ0oz/3CSMr8gMj6y9JxTliydu33Ckp7 w/dGY1AEBQKcesBTDDtzzCVWYUA5BI444jDxzh5uXcXh6wFbUe9C6GzpFPQ9X2sDnGxX c8EBb84UfbsnNzKlC2yRpELK9f09lqh+AcWLJ7uySUGeWR8wi8pKDiwBROzzQ86rSOEO 9RvTbnwBKFEbN1KBaddE67d7Hrhz6GGowWMJzwaDRO6uhzBXm9w3dWbvP+Hg9WKMGkWJ znGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589171; x=1695193971; 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=tx5cwCcgwsE/VDoxUQV5N86Hk7Oe81f9AvXImzVF+5A=; b=rqcu2NLdvRJpulxzck/paLF7HanN2ZvsRyG/poU5EHHK12y1PZyX7ARKpUHgRBr/JG YMTLsuX6Zfo2I0DyaJkSX93mPutleVXGMbbc8SpICihwJXePnfcmWvcFEZ4tC0Kx/Pa4 /tCTDK9lVzmQ9I1Ho0Yd7oZYlHpCKMl2TJEfjU1lf9YeL4il/Z8InDUlhnzV+x+0T+N8 z3kT+tSW6LHjcbsYKTXaxCRYb48FfWYajAzsGTctBn+/5FfTPDNEkc30HPk05UgxqBMr 6bwQBiuTaQiEN2Br1uQW3cFDbTzxPhuD9Q3X8eZ/jG/nJtyY5huGZKUfGJ+9EPdQ4t6P sq1g== X-Gm-Message-State: AOJu0YzO0fSq9qHLvMHQvuwiIClzC+97HQnzXqBYnpoP+HDZe/os0JDG Lg2IEy0FJifc0Dd56IBwzanj5LP0Uu2Byqgg57U= X-Google-Smtp-Source: AGHT+IEMhxSUp2FNgMOJZyxM9fQQdmleP3KPq97xLWjQyHx8HtnMmaKT5/fTZL3dWew6dTb5qELIug== X-Received: by 2002:a7b:c44e:0:b0:401:c0ef:c287 with SMTP id l14-20020a7bc44e000000b00401c0efc287mr1282784wmi.27.1694589171068; Wed, 13 Sep 2023 00:12:51 -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 x20-20020a05600c2a5400b003fe601a7d46sm1098719wme.45.2023.09.13.00.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:50 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 03/12] net/mlx5: Lift reload limitation when SFs are present Date: Wed, 13 Sep 2023 09:12:34 +0200 Message-ID: <20230913071243.930265-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Historically, the shared devlink_mutex prevented devlink instances from being registered/unregistered during another devlink instance reload operation. However, devlink_muxex is gone for some time now, this limitation is no longer needed. Lift it. Signed-off-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlx5/core/devlink.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c index af8460bb257b..3e064234f6fe 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c @@ -138,7 +138,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change, { struct mlx5_core_dev *dev = devlink_priv(devlink); struct pci_dev *pdev = dev->pdev; - bool sf_dev_allocated; int ret = 0; if (mlx5_dev_is_lightweight(dev)) { @@ -148,16 +147,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change, return 0; } - sf_dev_allocated = mlx5_sf_dev_allocated(dev); - if (sf_dev_allocated) { - /* Reload results in deleting SF device which further results in - * unregistering devlink instance while holding devlink_mutext. - * Hence, do not support reload. - */ - NL_SET_ERR_MSG_MOD(extack, "reload is unsupported when SFs are allocated"); - return -EOPNOTSUPP; - } - if (mlx5_lag_is_active(dev)) { NL_SET_ERR_MSG_MOD(extack, "reload is unsupported in Lag mode"); return -EOPNOTSUPP; From patchwork Wed Sep 13 07:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382526 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 DC75A182A3 for ; Wed, 13 Sep 2023 07:12:54 +0000 (UTC) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CFE81728 for ; Wed, 13 Sep 2023 00:12:54 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31aeef88a55so6007437f8f.2 for ; Wed, 13 Sep 2023 00:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589172; x=1695193972; 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=PPUEIwNx71s3eWjcIHfx8aNZVUmLM22niP2i+9vR93c=; b=al4WkwwVYM4nqNvQ82uF60cri/3qTgguU+QOa+3zKrD7/f59mVfpX4lflHnR3HQbCO TBK4CHhJJpOkPepoNt4QsU+5kvhjg2MrO5uXNMjRGYnhee24RTNxg+iOul2hQfpm/Hvb GEZoHelA5mgnUNBAkehUKKiVicYQ3/w9iFcp6GnLWEd108cn/Wpbhmrhv+i+SiucvBdW l3aBiYPzR8q9eo9dzDGM8qft4cAF0qvXtM7KkVDk46ZX7wOwfp4QFWmG5pYiqpvGGbnU GaWYij5EkKl746K+f4VsG83pqkLEbWPZnnYI9Jecpo+mOyVIXk9GDaUHfnmPc+/Qjzon 9AOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589172; x=1695193972; 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=PPUEIwNx71s3eWjcIHfx8aNZVUmLM22niP2i+9vR93c=; b=OcxgfWc8vYg+Eo0V7qGDploAkOe5uFxXoVK4A7JZ6CaMaechL6/4lhPYBQgbwy/PmP WsGgrKfyVK4vJlMur0TWUYlGCJSFP9a7jewcwgkK+R+oubTaJ4O8M2qlKVrS0Ue9ShKQ iSbEhU9zbTLA03Q6zZA1+BRRtf+n7803q27VVEvSaiAvdXACH0ZrENdIXE3sJrZXgOf4 NvmJIXSEqXfYP+ILRmbasExtWbwLDBFi16l2n+kjXyq0L4/Iz9B2xt+vwJ64t8vNvmWZ T7RLJhXSqCRoZ7QaBEYFlIeNKSixtfQuXyYVkj+54Cw7nyUFc6HxOrKCEuarBuqiprRq DVng== X-Gm-Message-State: AOJu0YwfEU8LeEr+jq6H5TOgI0HTG2shSkFRFCv+EWVlKIVopi2GGZOs vNbvKZnBtDwaTwqT9oyy670vAkqHG+pMuqnH4BQ= X-Google-Smtp-Source: AGHT+IGXTYFNIzApQa/tfZExtrc7xRaGySZIhOB5sRg4nVAzee5Ynq0MgDtB2kLD5MhyUGtICPIovw== X-Received: by 2002:a5d:6ac3:0:b0:314:2fdd:28ef with SMTP id u3-20020a5d6ac3000000b003142fdd28efmr1368501wrw.18.1694589172729; Wed, 13 Sep 2023 00:12:52 -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 g3-20020a5d6983000000b003197c7d08ddsm14680861wru.71.2023.09.13.00.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:52 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 04/12] devlink: put netnsid to nested handle Date: Wed, 13 Sep 2023 09:12:35 +0200 Message-ID: <20230913071243.930265-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko If netns of devlink instance and nested devlink instance differs, put netnsid attr to indicate that. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- net/devlink/linecard.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c index a0210ba56f2d..f95abdc93c66 100644 --- a/net/devlink/linecard.c +++ b/net/devlink/linecard.c @@ -65,7 +65,8 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) return devlink_linecard_get_from_attrs(devlink, info->attrs); } -static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *devlink) +static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, + struct devlink *devlink) { struct nlattr *nested_attr; @@ -74,6 +75,13 @@ static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *dev 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); + + if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id)) + return -EMSGSIZE; + } nla_nest_end(msg, nested_attr); return 0; @@ -131,7 +139,8 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, } if (linecard->nested_devlink && - devlink_nl_put_nested_handle(msg, linecard->nested_devlink)) + devlink_nl_put_nested_handle(msg, devlink_net(devlink), + linecard->nested_devlink)) goto nla_put_failure; genlmsg_end(msg, hdr); From patchwork Wed Sep 13 07:12:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382527 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 8E59418AF2 for ; Wed, 13 Sep 2023 07:12:56 +0000 (UTC) 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 B93771728 for ; Wed, 13 Sep 2023 00:12:55 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-401187f8071so3679275e9.0 for ; Wed, 13 Sep 2023 00:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589174; x=1695193974; 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=ASAR/arMUmymIcDXlTOqKsCopHPCwfPkt1/CsXfCTRU=; b=J9hIBtQAE2PvFGfWc7Ch0n8sHgu1Yu4rjjej/nYqowc2JLmuHUhNRHLmk30VG30gy5 VhKuDBZoru45XWkl8VrfTXSfJMqFZ1IGfMt8Q68HFTGH4mS42B5Ze3OwfhIimKxVchQ8 bbRlVRIt+KkyPnb7ApiOCE4l4WWAie0DqT0znahfHCYv+dwF4vsKCdYAxzMFBId77kG2 Li17+WHCOAGsEJSBVFc4YTZA5kbUAXZVn7+PH85zvyPvzilD7+4PWoZb2dwvT49KvsUE 8ZfRe8+2NeLvgW4JNSaSWvxfTzEcPsfoNHbs88ReJtZMi4A2bE9E41CSTXLkwyYIazi9 T02w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589174; x=1695193974; 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=ASAR/arMUmymIcDXlTOqKsCopHPCwfPkt1/CsXfCTRU=; b=N/bM4gOQHwZBZOzmQzrNczZ5xT3PYlT2bibNTlr5zOjXHBlwE3wQWdIK1TH88nD5sl K6Qf8EYAO4jH29BPmog3qIqSP1+y9j1sEjUMjA+6I5jFStxzm3sqNGCbWT5QdZplxZO/ gVACaQQ3mjbsD2b7BMpBevYf+Ecn/A5r3k2gNzkKlCXnTNcFJhHOWH4jMMWBOnHzQ362 AKnDttVJeaKbAMhjXbY/DKJ/R6gXGrXBrkk2HY0/tnKhd0PaVWeT99rhQZks51eUpHLF A4B4DLn3yl2Mx1tLSpsO9fLQNxa2dctncw5ZDcFKfrLwm0bs9r9JMkHhlVHeXWU0Xu3w DXkw== X-Gm-Message-State: AOJu0Yy1mTqpIcBSS2Wl6BEdyojU1sxk6RoXXxBPjxKgmYEMISjoMxkn TSLRI7VsQuiW4PDkhp9ca4+thKexLZ+PZf8cKbw= X-Google-Smtp-Source: AGHT+IHhVnxQeVYVbZDCF5jof2xDL2LyT6uHSTsdqYN2tEnXmpZyDZze824GcMRV+BJ9FQQzzeitgw== X-Received: by 2002:a05:600c:3d87:b0:3fe:f4b0:634a with SMTP id bi7-20020a05600c3d8700b003fef4b0634amr3688659wmb.19.1694589174296; Wed, 13 Sep 2023 00:12:54 -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 18-20020a05600c235200b00402f745c5ffsm1133472wmq.8.2023.09.13.00.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:53 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c Date: Wed, 13 Sep 2023 09:12:36 +0200 Message-ID: <20230913071243.930265-6-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko As the next patch is going to call this helper out of the linecard.c, move to netlink.c. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 2 ++ net/devlink/linecard.c | 26 -------------------------- net/devlink/netlink.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 1b05c2c09e27..fbf00de1accf 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -145,6 +145,8 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) return 0; } +int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, + struct devlink *devlink); int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info); /* Notify */ diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c index f95abdc93c66..688e89daee6a 100644 --- a/net/devlink/linecard.c +++ b/net/devlink/linecard.c @@ -65,32 +65,6 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) return devlink_linecard_get_from_attrs(devlink, info->attrs); } -static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, - struct devlink *devlink) -{ - struct nlattr *nested_attr; - - nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK); - 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); - - if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id)) - return -EMSGSIZE; - } - - nla_nest_end(msg, nested_attr); - return 0; - -nla_put_failure: - nla_nest_cancel(msg, nested_attr); - return -EMSGSIZE; -} - struct devlink_linecard_type { const char *type; const void *priv; diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index fc3e7c029a3b..48b5cfc2842f 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -82,6 +82,32 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG }, }; +int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, + struct devlink *devlink) +{ + struct nlattr *nested_attr; + + nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK); + 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); + + if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id)) + return -EMSGSIZE; + } + + nla_nest_end(msg, nested_attr); + return 0; + +nla_put_failure: + nla_nest_cancel(msg, nested_attr); + return -EMSGSIZE; +} + int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info) { int err; From patchwork Wed Sep 13 07:12:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382528 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 8EA1118AF2 for ; Wed, 13 Sep 2023 07:12:58 +0000 (UTC) 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 73D8A1728 for ; Wed, 13 Sep 2023 00:12:57 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-401b5516104so68441775e9.2 for ; Wed, 13 Sep 2023 00:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589176; x=1695193976; 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=dqkQ0rNxlqlnSBJNC6M4MIiSS3iN/iafF3G9ARoJuF0=; b=L4RH/HRU4QF7My8vs5TSMl/ux/7Imku4ZrNjcQMasJ52s9tmdDdrt+gG1Wn6etQ7uh BQfglHnEVLaou1nlxWUs6fv/B6oJ+O+wiEosTRI1mvFCwpRpLO1M9DVNuu1TsXYXo/py maSgnIt3wi4Cfvdp69ivKz+GFn9iqKD1ebWpcd2ntlM0Talu11BJ3i5g11kJFcorFM6E BpoU2p1VRQQlA9Rvdw/EJ/MhnCa64t2ncQhZI2EhHwWHxL0okpAmAaowMbM2XNKZVObJ 0reKohJXQTxTPfnGi7RxvcGMybEUt2NRfUiekslyTq2dR8t4PpOWU0SIWu0LT30E2TQA uOkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589176; x=1695193976; 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=dqkQ0rNxlqlnSBJNC6M4MIiSS3iN/iafF3G9ARoJuF0=; b=cwKRrj2Phq2w9mmKamZll0hTkO2aFweoZlczPO6zF4RIEGvhPalI8UXbfy9feUbYTg iKHuM2wX5AssXrlop2BiJmD4DaQtvm4RdRHP01V+cskdqZVXmUjSOEPkADEcBH0jAt3O bvaR4TXMN2nHH1S53ydXPOacbckwIz6b6qd4qf7UK2eVSTpNFBjlTa9yPGZqGRWMVzcx hBlcPDxZyfsEFfC6uePMq/E6N0WNQ7liy6c2HK6/eNcfBZoiYyN4NVK7a1UFKNiY+dpJ /JZjl1MMsPafT+wlJec3Xe/CmhDPEezwYXO1GntYDN44PEDdv5BRX5okMJIe+3ZdsL8G 6F9A== X-Gm-Message-State: AOJu0YzRVi9bTydQfQb79RfT1i5NR2a1LIPubcGMxkq10fsyJkd10A7B Syquqh5l/P8JuAY8E8l+VFdYK2Ubt9wGBWZq33w= X-Google-Smtp-Source: AGHT+IFITjilultJWk8vk4m8q+MooiOK8Z8jvT2bdNx6c1euK3HtbRgH5Q/j6T3apoP72Nhoh3V5uQ== X-Received: by 2002:a05:600c:221a:b0:401:dc7c:2488 with SMTP id z26-20020a05600c221a00b00401dc7c2488mr1313440wml.11.1694589176010; Wed, 13 Sep 2023 00:12:56 -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 c4-20020a05600c0ac400b004030c778396sm1144220wmr.4.2023.09.13.00.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:55 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg Date: Wed, 13 Sep 2023 09:12:37 +0200 Message-ID: <20230913071243.930265-7-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko As the next patch is going to call this helper with need to fill another type of nested attribute, pass it over function arg. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- net/devlink/devl_internal.h | 2 +- net/devlink/linecard.c | 3 ++- net/devlink/netlink.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index fbf00de1accf..53449dbd6545 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -146,7 +146,7 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) } int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, - struct devlink *devlink); + struct devlink *devlink, int attrtype); int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info); /* Notify */ diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c index 688e89daee6a..36170f466878 100644 --- a/net/devlink/linecard.c +++ b/net/devlink/linecard.c @@ -114,7 +114,8 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, if (linecard->nested_devlink && devlink_nl_put_nested_handle(msg, devlink_net(devlink), - linecard->nested_devlink)) + linecard->nested_devlink, + DEVLINK_ATTR_NESTED_DEVLINK)) goto nla_put_failure; genlmsg_end(msg, hdr); diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 48b5cfc2842f..499304d9de49 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -83,11 +83,11 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { }; int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net, - struct devlink *devlink) + struct devlink *devlink, int attrtype) { struct nlattr *nested_attr; - nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK); + nested_attr = nla_nest_start(msg, attrtype); if (!nested_attr) return -EMSGSIZE; if (devlink_nl_put_handle(msg, devlink)) From patchwork Wed Sep 13 07:12:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382529 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 6194918AF2 for ; Wed, 13 Sep 2023 07:13:00 +0000 (UTC) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9C71728 for ; Wed, 13 Sep 2023 00:12:59 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so3303935e9.1 for ; Wed, 13 Sep 2023 00:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589178; x=1695193978; 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=ndjapu7lUqG7eBQABHUGS9K2IG06doKEDZs025wsSzg=; b=XiLwkSRuOfNUxqLRcdacXL2qjKSbNIti5v2ws5XTltF8pxb5yp0JgggJmomV7MjtRG r8klTuhWdA7RqaKbYz8bVURWl4vaHK/5BbJawosrD0v8PN3qSXilbWS1Q9tvblOjBobm anUZv1V1/wnrDjJR/PxwxiD+nr0UmU+W7v9UOpe/h/eKr7ju/lEPp1/BLS5xL167Mb/X azNFFfxM9xfCy7MwYEHJHW5IikpBYem1XBfZIRtmTcdJ3G9eTwfvx8Z9ZQFwTbvy7xHN 5GIBM1au1hLLgdDGpofB4+kHaQfo49dxhAnnI0GxlzVXsGgiUd8lzDwSSponuB5cTckH t4Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589178; x=1695193978; 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=ndjapu7lUqG7eBQABHUGS9K2IG06doKEDZs025wsSzg=; b=JVH5vuEpEAz1Jqgt0HSFhnsy/M3x/4nCViQ4TXhxuE2LvuK4WSelUFkc8IQoQZUCo4 QhGawn7vbRbxKytZrYQmdG2r9h94KuBJHAPYnqF5SXHPTZ2em/V5PINbiyu1jSdWgDmM Va1B4rVIy4udRocS7LcXyjnLwkSluTtVadnwYcNPXh2iAiWCxJHrFDlrnbfhGeKJI+q9 6zFb184+0Fpewzs8HGOoxQNOpj9AYRAt7D/uzu/k/2Gw12SBQ2mFlDLWQfUHHQeFN6VK cWjv5UX1UQmC3aAX9YBfSnmgj0m3l4SKqA4udE1+48cJhPwONqXEN5VQpXCiT1WpvMFy uinA== X-Gm-Message-State: AOJu0YzvR7u4c8A6NCTofeVOqnEznMak3y94LvzuyTo3xDhu27o1P+ao dn35UfDmhfthmCMxvtHjw/hcsN0RjfaGKuXjDt0= X-Google-Smtp-Source: AGHT+IFljqo/cvtpw/cw7b+7oqZAkSzR+hGkmjKYEB1S7wiUe4BNhK5+iY8tEKcGyIQscg6bOQ0RYQ== X-Received: by 2002:a7b:c8ce:0:b0:3fe:1fd9:bedf with SMTP id f14-20020a7bc8ce000000b003fe1fd9bedfmr1283443wml.11.1694589177742; Wed, 13 Sep 2023 00:12:57 -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 az17-20020a05600c601100b003feea62440bsm1124161wmb.43.2023.09.13.00.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:57 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 07/12] devlink: introduce object and nested devlink relationship infra Date: Wed, 13 Sep 2023 09:12:38 +0200 Message-ID: <20230913071243.930265-8-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko It is a bit tricky to maintain relationship between devlink objects and nested devlink instances due to following aspects: 1) Locking. It is necessary to lock the devlink instance that contains the object first, only after that to lock the nested instance. 2) Lifetimes. Objects (e.g devlink port) may be removed before the nested devlink instance. 3) Notifications. If nested instance changes (e.g. gets registered/unregistered) the nested-in object needs to send appropriate notifications. Resolve this by introducing an xarray that holds 1:1 relationships between devlink object and related nested devlink instance. Use that xarray index to get the object/nested devlink instance on the other side. Provide necessary helpers: devlink_rel_nested_in_add/clear() to add and clear the relationship. devlink_rel_nested_in_notify() to call the nested-in object to send notifications during nested instance register/unregister/netns change. devlink_rel_devlink_handle_put() to be used by nested-in object fill function to fill the nested handle. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- net/devlink/core.c | 215 ++++++++++++++++++++++++++++++++++++ net/devlink/dev.c | 1 + net/devlink/devl_internal.h | 17 +++ 3 files changed, 233 insertions(+) diff --git a/net/devlink/core.c b/net/devlink/core.c index 6cec4afb01fb..2a98ff9a2f6b 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -16,6 +16,219 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(devlink_trap_report); DEFINE_XARRAY_FLAGS(devlinks, XA_FLAGS_ALLOC); +static struct devlink *devlinks_xa_get(unsigned long index) +{ + struct devlink *devlink; + + rcu_read_lock(); + devlink = xa_find(&devlinks, &index, index, DEVLINK_REGISTERED); + if (!devlink || !devlink_try_get(devlink)) + devlink = NULL; + rcu_read_unlock(); + return devlink; +} + +/* devlink_rels xarray contains 1:1 relationships between + * devlink object and related nested devlink instance. + * The xarray index is used to get the nested object from + * the nested-in object code. + */ +static DEFINE_XARRAY_FLAGS(devlink_rels, XA_FLAGS_ALLOC1); + +#define DEVLINK_REL_IN_USE XA_MARK_0 + +struct devlink_rel { + u32 index; + refcount_t refcount; + u32 devlink_index; + struct { + u32 devlink_index; + u32 obj_index; + devlink_rel_notify_cb_t *notify_cb; + devlink_rel_cleanup_cb_t *cleanup_cb; + struct work_struct notify_work; + } nested_in; +}; + +static void devlink_rel_free(struct devlink_rel *rel) +{ + xa_erase(&devlink_rels, rel->index); + kfree(rel); +} + +static void __devlink_rel_get(struct devlink_rel *rel) +{ + refcount_inc(&rel->refcount); +} + +static void __devlink_rel_put(struct devlink_rel *rel) +{ + if (refcount_dec_and_test(&rel->refcount)) + devlink_rel_free(rel); +} + +static void devlink_rel_nested_in_notify_work(struct work_struct *work) +{ + struct devlink_rel *rel = container_of(work, struct devlink_rel, + nested_in.notify_work); + struct devlink *devlink; + + devlink = devlinks_xa_get(rel->nested_in.devlink_index); + if (!devlink) + goto rel_put; + if (!devl_trylock(devlink)) { + devlink_put(devlink); + goto reschedule_work; + } + if (!devl_is_registered(devlink)) { + devl_unlock(devlink); + devlink_put(devlink); + goto rel_put; + } + if (!xa_get_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE)) + rel->nested_in.cleanup_cb(devlink, rel->nested_in.obj_index, rel->index); + rel->nested_in.notify_cb(devlink, rel->nested_in.obj_index); + devl_unlock(devlink); + devlink_put(devlink); + +rel_put: + __devlink_rel_put(rel); + return; + +reschedule_work: + schedule_work(&rel->nested_in.notify_work); +} + +static void devlink_rel_nested_in_notify_work_schedule(struct devlink_rel *rel) +{ + __devlink_rel_get(rel); + schedule_work(&rel->nested_in.notify_work); +} + +static struct devlink_rel *devlink_rel_alloc(void) +{ + struct devlink_rel *rel; + static u32 next; + int err; + + rel = kzalloc(sizeof(*rel), GFP_KERNEL); + if (!rel) + return ERR_PTR(-ENOMEM); + + err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel, + xa_limit_32b, &next, GFP_KERNEL); + if (err) { + kfree(rel); + return ERR_PTR(err); + } + + refcount_set(&rel->refcount, 1); + INIT_WORK(&rel->nested_in.notify_work, + &devlink_rel_nested_in_notify_work); + return rel; +} + +static void devlink_rel_put(struct devlink *devlink) +{ + struct devlink_rel *rel = devlink->rel; + + if (!rel) + return; + xa_clear_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE); + devlink_rel_nested_in_notify_work_schedule(rel); + __devlink_rel_put(rel); + devlink->rel = NULL; +} + +void devlink_rel_nested_in_clear(u32 rel_index) +{ + xa_clear_mark(&devlink_rels, rel_index, DEVLINK_REL_IN_USE); +} + +int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index, + u32 obj_index, devlink_rel_notify_cb_t *notify_cb, + devlink_rel_cleanup_cb_t *cleanup_cb, + struct devlink *devlink) +{ + struct devlink_rel *rel = devlink_rel_alloc(); + + ASSERT_DEVLINK_NOT_REGISTERED(devlink); + + if (IS_ERR(rel)) + return PTR_ERR(rel); + + rel->devlink_index = devlink->index; + rel->nested_in.devlink_index = devlink_index; + rel->nested_in.obj_index = obj_index; + rel->nested_in.notify_cb = notify_cb; + rel->nested_in.cleanup_cb = cleanup_cb; + *rel_index = rel->index; + xa_set_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE); + devlink->rel = rel; + return 0; +} + +void devlink_rel_nested_in_notify(struct devlink *devlink) +{ + struct devlink_rel *rel = devlink->rel; + + if (!rel) + return; + devlink_rel_nested_in_notify_work_schedule(rel); +} + +static struct devlink_rel *devlink_rel_find(unsigned long rel_index) +{ + return xa_find(&devlink_rels, &rel_index, rel_index, + DEVLINK_REL_IN_USE); +} + +static struct devlink *devlink_rel_devlink_get_lock(u32 rel_index) +{ + struct devlink *devlink; + struct devlink_rel *rel; + u32 devlink_index; + + if (!rel_index) + return NULL; + xa_lock(&devlink_rels); + rel = devlink_rel_find(rel_index); + if (rel) + devlink_index = rel->devlink_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; +} + +int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, + u32 rel_index, int attrtype, + bool *msg_updated) +{ + struct net *net = devlink_net(devlink); + struct devlink *rel_devlink; + int err; + + rel_devlink = devlink_rel_devlink_get_lock(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; + return err; +} + void *devlink_priv(struct devlink *devlink) { return &devlink->priv; @@ -142,6 +355,7 @@ int devl_register(struct devlink *devlink) xa_set_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); devlink_notify_register(devlink); + devlink_rel_nested_in_notify(devlink); return 0; } @@ -166,6 +380,7 @@ void devl_unregister(struct devlink *devlink) devlink_notify_unregister(devlink); xa_clear_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); + devlink_rel_put(devlink); } EXPORT_SYMBOL_GPL(devl_unregister); diff --git a/net/devlink/dev.c b/net/devlink/dev.c index bba4ace7d22b..3ae26d9088ab 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -372,6 +372,7 @@ static void devlink_reload_netns_change(struct devlink *devlink, devlink_notify_unregister(devlink); write_pnet(&devlink->_net, dest_net); devlink_notify_register(devlink); + devlink_rel_nested_in_notify(devlink); } int devlink_reload(struct devlink *devlink, struct net *dest_net, diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 53449dbd6545..4cb534aff44d 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -17,6 +17,8 @@ #include "netlink_gen.h" +struct devlink_rel; + #define DEVLINK_REGISTERED XA_MARK_1 #define DEVLINK_RELOAD_STATS_ARRAY_SIZE \ @@ -55,6 +57,7 @@ struct devlink { u8 reload_failed:1; refcount_t refcount; struct rcu_work rwork; + struct devlink_rel *rel; char priv[] __aligned(NETDEV_ALIGN); }; @@ -92,6 +95,20 @@ static inline bool devl_is_registered(struct devlink *devlink) return xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); } +typedef void devlink_rel_notify_cb_t(struct devlink *devlink, u32 obj_index); +typedef void devlink_rel_cleanup_cb_t(struct devlink *devlink, u32 obj_index, + u32 rel_index); + +void devlink_rel_nested_in_clear(u32 rel_index); +int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index, + u32 obj_index, devlink_rel_notify_cb_t *notify_cb, + devlink_rel_cleanup_cb_t *cleanup_cb, + struct devlink *devlink); +void devlink_rel_nested_in_notify(struct devlink *devlink); +int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, + u32 rel_index, int attrtype, + bool *msg_updated); + /* Netlink */ #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) From patchwork Wed Sep 13 07:12:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382530 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 47C5018C22 for ; Wed, 13 Sep 2023 07:13:02 +0000 (UTC) Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8080D1728 for ; Wed, 13 Sep 2023 00:13:01 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50091b91a83so10604984e87.3 for ; Wed, 13 Sep 2023 00:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589180; x=1695193980; 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=V1bT9y8w37q/lqO7jWhPz/MCizYdOi4GhRkpzRZ8STo=; b=H3axmAZzMYVlsDoMA4ai51J+JXwP1MHv9cBYXAeTXCAPIiMEJ5iR5C961+Eqh6dyJa Khei+h3+kF72daKekWqqOv5LSV21LUCVjT+6/cDEYLnJjYgR3QPwguV37rS06dsGLNg8 6ffLTdZFD2LbBKLVljM34lLjDvKIgwV2iwGfn5MvjX/F/q5DpbqOdby1xzr3ppmhDqVu qMvpAMDGwL+65k27enlOBwYxW9aBoeV1lUbsiHdOjNLQOl4WO9ruvHtFm5z4wJIwGU9O q5NdSsVLC4nelM/bEHVn7uVfdYTwYkqYR5iBWQBCWe4/aSSp2pWDhkfuX3XGbUZfyj1o +pwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589180; x=1695193980; 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=V1bT9y8w37q/lqO7jWhPz/MCizYdOi4GhRkpzRZ8STo=; b=IxBv7nD9xRRaq6EZRFpqZXNG530cWzY593usI0+lAmteVwOATYQzHJIFEKN+Y62Ppb Bt2PZr1ngJXCqIbIekqJ2Ra8j2+CUpRAla34KNEA4ABFMgYRgWFD5PBoB4a0xn1+9zqv dQV9oCkrga1djr9LcBcdrdMhVc4jFJwUasrRDl6PbBur8ZlLk8UrsdAKY0q4GH3fjDl9 S7iH/ElWxz61EZ/rYAdozS3tCxW/7D/vJpUtCC7/dHymIEHSsvmWbB8hA7nhgMhyT9Fq cSZRgf1hZLcuSPFOFBMXYTTn3QBnygEGoGA6J1iF7f9KJVxcORvAMen+aMcjDBxuWVsS UMYg== X-Gm-Message-State: AOJu0YxGogJZYXTkH1XRwfK/3Oj0C9xAOrF/qs769Skzqr8Nqtik0fj3 snwN9KBCEQJQ8mSc7+05c+XfPJBOS16crCteOQ8= X-Google-Smtp-Source: AGHT+IGtZHMYbT255bHbYyb1Y1eoVQqwOABQajlX+UkYvc41jFozXUm3VUt+1Y5ij29G9g2icyooWQ== X-Received: by 2002:a05:6512:3088:b0:4fe:95e:159a with SMTP id z8-20020a056512308800b004fe095e159amr1659956lfd.23.1694589179608; Wed, 13 Sep 2023 00:12:59 -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 m7-20020a05600c280700b003fed630f560sm1114662wmb.36.2023.09.13.00.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:12:59 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 08/12] devlink: expose peer SF devlink instance Date: Wed, 13 Sep 2023 09:12:39 +0200 Message-ID: <20230913071243.930265-9-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce a new helper devl_port_fn_devlink_set() to be used by driver assigning a devlink instance to the peer devlink port function. Expose this to user over new netlink attribute nested under port function nest to expose devlink handle related to the port function. This is particularly helpful for user to understand the relationship between devlink instances created for SFs and the port functions they belong to. Note that caller of devlink_port_notify() needs to hold devlink instance lock, put the assertion to devl_port_fn_devlink_set() to make this requirement explicit. Also note the limitations that only allow to make this assignment for registered objects. Signed-off-by: Jiri Pirko --- v1->v2: - rebased on top of previous patch - utilize newly added rel infra - split devlink_nl_put_nested_handle() arg extension into separate patch --- include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/devlink/port.c | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 29fd1b4ee654..2655ab6101ec 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -150,6 +150,7 @@ struct devlink_port { struct devlink_rate *devlink_rate; struct devlink_linecard *linecard; + u32 rel_index; }; struct devlink_port_new_attrs { @@ -1697,6 +1698,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 controller, u16 pf, u32 sf, bool external); +int devl_port_fn_devlink_set(struct devlink_port *devlink_port, + struct devlink *fn_devlink); struct devlink_rate * devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name, struct devlink_rate *parent); diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 03875e078be8..cd4b82458d1b 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -680,6 +680,7 @@ enum devlink_port_function_attr { DEVLINK_PORT_FN_ATTR_STATE, /* u8 */ DEVLINK_PORT_FN_ATTR_OPSTATE, /* u8 */ DEVLINK_PORT_FN_ATTR_CAPS, /* bitfield32 */ + DEVLINK_PORT_FN_ATTR_DEVLINK, /* nested */ __DEVLINK_PORT_FUNCTION_ATTR_MAX, DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1 diff --git a/net/devlink/port.c b/net/devlink/port.c index 7b300a322ed9..4e9003242448 100644 --- a/net/devlink/port.c +++ b/net/devlink/port.c @@ -428,6 +428,13 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por if (err) goto out; err = devlink_port_fn_state_fill(port, msg, extack, &msg_updated); + if (err) + goto out; + err = devlink_rel_devlink_handle_put(msg, port->devlink, + port->rel_index, + DEVLINK_PORT_FN_ATTR_DEVLINK, + &msg_updated); + out: if (err || !msg_updated) nla_nest_cancel(msg, function_attr); @@ -1392,6 +1399,50 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro } EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set); +static void devlink_port_rel_notify_cb(struct devlink *devlink, u32 port_index) +{ + struct devlink_port *devlink_port; + + devlink_port = devlink_port_get_by_index(devlink, port_index); + if (!devlink_port) + return; + devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); +} + +static void devlink_port_rel_cleanup_cb(struct devlink *devlink, u32 port_index, + u32 rel_index) +{ + struct devlink_port *devlink_port; + + devlink_port = devlink_port_get_by_index(devlink, port_index); + if (devlink_port && devlink_port->rel_index == rel_index) + devlink_port->rel_index = 0; +} + +/** + * devl_port_fn_devlink_set - Attach peer devlink + * instance to port function. + * @devlink_port: devlink port + * @fn_devlink: devlink instance to attach + */ +int devl_port_fn_devlink_set(struct devlink_port *devlink_port, + struct devlink *fn_devlink) +{ + ASSERT_DEVLINK_PORT_REGISTERED(devlink_port); + + if (WARN_ON(devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_SF || + devlink_port->attrs.pci_sf.external)) + return -EINVAL; + + return devlink_rel_nested_in_add(&devlink_port->rel_index, + devlink_port->devlink->index, + devlink_port->index, + devlink_port_rel_notify_cb, + devlink_port_rel_cleanup_cb, + fn_devlink); +} +EXPORT_SYMBOL_GPL(devl_port_fn_devlink_set); + /** * devlink_port_linecard_set - Link port with a linecard * From patchwork Wed Sep 13 07:12:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382531 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 AA9A718C22 for ; Wed, 13 Sep 2023 07:13:03 +0000 (UTC) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B443D1728 for ; Wed, 13 Sep 2023 00:13:02 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-401f68602a8so70190085e9.3 for ; Wed, 13 Sep 2023 00:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589181; x=1695193981; 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=a8ziZqPNFzCo0A/K8YJyf25Kw4mrfTiAr0OWYfFnf4A=; b=FtPTmgE1SrXOrzWya43pLqMwiYHqbkFOVMSWfxDv1bDVyVjN+PKOlO2hGZfh1PYa2N WR/HHoWP/piXIpJNM/vUibYatdwjXBNXg7r6NTXa1REv5a73xXuitRoqjwyITA7dPGbN DRN1V8q9Hm809FJEo/deRJd2OTab6DJ5g/qwsZsVfkTxF79XdoB9O+EusgJ+si8fufYO 6SM71Lb9KlVG30rgIiccPIW/rWtrin/JoufaZYhSIGiAbj08/WwwOH03b6KzlLb+vhmN dA10SdVT3xgPZBrjNKUcZCx0pKcxlUsizEBgxrih7VMfekBN3z0FpzRnJezCT5zQefRF WTXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589181; x=1695193981; 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=a8ziZqPNFzCo0A/K8YJyf25Kw4mrfTiAr0OWYfFnf4A=; b=DFdFWMgdO8D5jYCVUpf+u4Y2Nxv8koujrue/P5B0N2W54VC2ahZA1qBwUxgv+I9wY1 gT9tNruwd0m6w2dcBvbVLq+QFBD3BFOYQB6BjwPu7Fw9+OW8j6PwAuXzfRNzO029Ikgd eQpv+lg+pLPoWUxwvZJj2RnSghLJbE7u2fiywMpQ2TNvzHsFxr7pYwh6LTKcy+EtJ4Cy TR+wU/2WgBPyOYxdzb+T02NvavvpGMqxdLHxyPJSO2j53kQEzP4hIVfWPZ9o2TqQaJa3 pJX2XnRh21RPq5azN20CakMKMM5Jh4ar25BzNSSJXoEMPHZJfW+H6TE7BNZeJVCudeVM t2YA== X-Gm-Message-State: AOJu0Yz3XTvxco/57UkWdxAJ6WYZSuOROtozfIkbn2vO56FGvDs0KKjP VerwYGLvu2FVktdsF0yrB/VxqgfiKkdtXx7FLLs= X-Google-Smtp-Source: AGHT+IEPyJ+Xq23VL7wKfNE4KR2dpfA9us2ADwQNId/OMbHy3H5wzv+Ji43/HvBCvWCgZ8OuJJkllA== X-Received: by 2002:a05:600c:1e1d:b0:401:cdc1:ac82 with SMTP id ay29-20020a05600c1e1d00b00401cdc1ac82mr1251221wmb.9.1694589181260; Wed, 13 Sep 2023 00:13:01 -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 24-20020a05600c021800b003fefe70ec9csm1134194wmi.10.2023.09.13.00.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:13:00 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port Date: Wed, 13 Sep 2023 09:12:40 +0200 Message-ID: <20230913071243.930265-10-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Benefit from the existence of internal mlx5 notifier and extend it by event MLX5_DRIVER_EVENT_SF_PEER_DEVLINK. Use this event from SF auxiliary device probe/remove functions to pass the registered SF devlink instance to the SF representor. Process the new event in SF representor code and call devl_port_fn_devlink_set() to do the assignments. Implement this in work to avoid possible deadlock when probe/remove function of SF may be called with devlink instance lock held during devlink reload. Signed-off-by: Jiri Pirko --- v1->v2: - rebased on top of net-next - removed work code as devl_port_fn_devlink_set() could be called without instance lock - propagate return code newly returned by devl_port_fn_devlink_set() --- .../ethernet/mellanox/mlx5/core/sf/dev/dev.h | 6 ++++ .../mellanox/mlx5/core/sf/dev/driver.c | 26 ++++++++++++++ .../ethernet/mellanox/mlx5/core/sf/devlink.c | 34 +++++++++++++++++++ include/linux/mlx5/device.h | 1 + 4 files changed, 67 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h index 2a66a427ef15..b99131e95e37 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h @@ -19,6 +19,12 @@ struct mlx5_sf_dev { u16 fn_id; }; +struct mlx5_sf_peer_devlink_event_ctx { + u16 fn_id; + struct devlink *devlink; + int err; +}; + void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev); void mlx5_sf_dev_table_destroy(struct mlx5_core_dev *dev); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c index 8fe82f1191bb..169c2c68ed5c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c @@ -8,6 +8,20 @@ #include "dev.h" #include "devlink.h" +static int mlx5_core_peer_devlink_set(struct mlx5_sf_dev *sf_dev, struct devlink *devlink) +{ + struct mlx5_sf_peer_devlink_event_ctx event_ctx = { + .fn_id = sf_dev->fn_id, + .devlink = devlink, + }; + int ret; + + ret = mlx5_blocking_notifier_call_chain(sf_dev->parent_mdev, + MLX5_DRIVER_EVENT_SF_PEER_DEVLINK, + &event_ctx); + return ret == NOTIFY_OK ? event_ctx.err : 0; +} + static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) { struct mlx5_sf_dev *sf_dev = container_of(adev, struct mlx5_sf_dev, adev); @@ -54,9 +68,21 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia mlx5_core_warn(mdev, "mlx5_init_one err=%d\n", err); goto init_one_err; } + + err = mlx5_core_peer_devlink_set(sf_dev, devlink); + if (err) { + mlx5_core_warn(mdev, "mlx5_core_peer_devlink_set err=%d\n", err); + goto peer_devlink_set_err; + } + devlink_register(devlink); return 0; +peer_devlink_set_err: + if (mlx5_dev_is_lightweight(sf_dev->mdev)) + mlx5_uninit_one_light(sf_dev->mdev); + else + mlx5_uninit_one(sf_dev->mdev); init_one_err: iounmap(mdev->iseg); remap_err: diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c index e34a8f88c518..964a5b1876f3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c @@ -28,6 +28,7 @@ struct mlx5_sf_table { struct mutex sf_state_lock; /* Serializes sf state among user cmds & vhca event handler. */ struct notifier_block esw_nb; struct notifier_block vhca_nb; + struct notifier_block mdev_nb; }; static struct mlx5_sf * @@ -511,6 +512,35 @@ static int mlx5_sf_esw_event(struct notifier_block *nb, unsigned long event, voi return 0; } +static int mlx5_sf_mdev_event(struct notifier_block *nb, unsigned long event, void *data) +{ + struct mlx5_sf_table *table = container_of(nb, struct mlx5_sf_table, mdev_nb); + struct mlx5_sf_peer_devlink_event_ctx *event_ctx = data; + int ret = NOTIFY_DONE; + struct mlx5_sf *sf; + + if (event != MLX5_DRIVER_EVENT_SF_PEER_DEVLINK) + return NOTIFY_DONE; + + table = mlx5_sf_table_try_get(table->dev); + if (!table) + return NOTIFY_DONE; + + mutex_lock(&table->sf_state_lock); + sf = mlx5_sf_lookup_by_function_id(table, event_ctx->fn_id); + if (!sf) + goto out; + + event_ctx->err = devl_port_fn_devlink_set(&sf->dl_port.dl_port, + event_ctx->devlink); + + ret = NOTIFY_OK; +out: + mutex_unlock(&table->sf_state_lock); + mlx5_sf_table_put(table); + return ret; +} + static bool mlx5_sf_table_supported(const struct mlx5_core_dev *dev) { return dev->priv.eswitch && MLX5_ESWITCH_MANAGER(dev) && @@ -544,6 +574,9 @@ int mlx5_sf_table_init(struct mlx5_core_dev *dev) if (err) goto vhca_err; + table->mdev_nb.notifier_call = mlx5_sf_mdev_event; + mlx5_blocking_notifier_register(dev, &table->mdev_nb); + return 0; vhca_err: @@ -562,6 +595,7 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev) if (!table) return; + mlx5_blocking_notifier_unregister(dev, &table->mdev_nb); mlx5_vhca_event_notifier_unregister(table->dev, &table->vhca_nb); mlx5_esw_event_notifier_unregister(dev->priv.eswitch, &table->esw_nb); WARN_ON(refcount_read(&table->refcount)); diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h index 4d5be378fa8c..8fbe22de16ef 100644 --- a/include/linux/mlx5/device.h +++ b/include/linux/mlx5/device.h @@ -366,6 +366,7 @@ enum mlx5_driver_event { MLX5_DRIVER_EVENT_UPLINK_NETDEV, MLX5_DRIVER_EVENT_MACSEC_SA_ADDED, MLX5_DRIVER_EVENT_MACSEC_SA_DELETED, + MLX5_DRIVER_EVENT_SF_PEER_DEVLINK, }; enum { From patchwork Wed Sep 13 07:12:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382532 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 2552A19BB4 for ; Wed, 13 Sep 2023 07:13:05 +0000 (UTC) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BFA11728 for ; Wed, 13 Sep 2023 00:13:04 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31f7400cb74so5567037f8f.2 for ; Wed, 13 Sep 2023 00:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589183; x=1695193983; 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=FITgGfcIW2lUxPsg1hCS5wkFztspz19RNuZ48xXFM9U=; b=KdWql8jMOmuo5y0K152JAfEugoV8ksZhB1v4cEVDzcrkzV0pFhWsm6PcoGOJZcljyP 9O39OFY8fRwN2B9DmjvwK3nhFqIPzVx7k1R/QGpzCWMIwMDEhqFuift+0At8w9Enptew Kq4qrqxq/PLW1tG6g7y6nxzUzSXK8jNsbu/I1oME/XRNLjj/OCbCLI/v8rLM2+JSvrvk 6eB10nxsaOIMnEMACEvJp/OCoyuhIugth/bPKUZzJOeODWBR430cx1r8bN97JS/QAnCL kXsq0/MHZZnjVGXf8OIv/1mL5dHZaPjIFdpolGSk9SHKPg1/asNOLYBXSeNF2LXwidH2 FpAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589183; x=1695193983; 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=FITgGfcIW2lUxPsg1hCS5wkFztspz19RNuZ48xXFM9U=; b=BlHjA2b+XNDMcisbLcIOQGeypw+U08vGXkcnDXZ3Z4HNspxO9wwjUf1c08xJPiXLiP BJgF1W+rFpAUpR/sKD1UcJ9Hf/RGEQvQ3YOLFKEDVI6yADfBvNnBgar/DZZplve/rYdv Le9V9cxnSOhaA9MU8AbyGsWpkvJOwKQfeqc24Y9CNUbyXJURss869D8T4rEHouE0Bo+j NCUYQdyMOrahG2qBQZe+UUTUWFTlCDcMRpv8ti8Rdh/goN6xef2c/Hik18WlkHZ7c6Py DgRq5UEqbDZAAbWF7VO6+RCucFtslbWPpc92cbw6qEEkQvzEwsXWEQ3EpSjDT5Wbp3pZ 7ZcQ== X-Gm-Message-State: AOJu0YxdQaE4q7fKFjk/birBI5Gjcc95RI1PqLG4Zt9VQTybtomzR6Av fn1KliskOfjfKo0dqe8ugyuMmHmrBzbmGfpGS8o= X-Google-Smtp-Source: AGHT+IHjLhkrBJB/tSi5FRW3QQOGbacgY1x6sjSOC3QjTL7tKXbSfHl0CGO/uqwVh/K6skLKltKTDw== X-Received: by 2002:adf:e350:0:b0:31a:d7ce:927a with SMTP id n16-20020adfe350000000b0031ad7ce927amr1219703wrj.3.1694589182860; Wed, 13 Sep 2023 00:13:02 -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 q28-20020a056000137c00b0031989784d96sm14693616wrz.76.2023.09.13.00.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:13:02 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 10/12] devlink: convert linecard nested devlink to new rel infrastructure Date: Wed, 13 Sep 2023 09:12:41 +0200 Message-ID: <20230913071243.930265-11-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Benefit from the newly introduced rel infrastructure, treat the linecard nested devlink instances in the same way as port function instances. Convert the code to use the rel infrastructure. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- .../mellanox/mlxsw/core_linecard_dev.c | 9 ++-- include/net/devlink.h | 4 +- net/devlink/linecard.c | 47 ++++++++++++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c index af37e650a8ad..e8d6fe35bf36 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c @@ -132,6 +132,7 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev, struct mlxsw_linecard *linecard = linecard_bdev->linecard; struct mlxsw_linecard_dev *linecard_dev; struct devlink *devlink; + int err; devlink = devlink_alloc(&mlxsw_linecard_dev_devlink_ops, sizeof(*linecard_dev), &adev->dev); @@ -141,8 +142,12 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev, linecard_dev->linecard = linecard_bdev->linecard; linecard_bdev->linecard_dev = linecard_dev; + err = devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink); + if (err) { + devlink_free(devlink); + return err; + } devlink_register(devlink); - devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink); return 0; } @@ -151,9 +156,7 @@ static void mlxsw_linecard_bdev_remove(struct auxiliary_device *adev) struct mlxsw_linecard_bdev *linecard_bdev = container_of(adev, struct mlxsw_linecard_bdev, adev); struct devlink *devlink = priv_to_devlink(linecard_bdev->linecard_dev); - struct mlxsw_linecard *linecard = linecard_bdev->linecard; - devlink_linecard_nested_dl_set(linecard->devlink_linecard, NULL); devlink_unregister(devlink); devlink_free(devlink); } diff --git a/include/net/devlink.h b/include/net/devlink.h index 2655ab6101ec..0dfcd7d7fa18 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1720,8 +1720,8 @@ void devlink_linecard_provision_clear(struct devlink_linecard *linecard); void devlink_linecard_provision_fail(struct devlink_linecard *linecard); void devlink_linecard_activate(struct devlink_linecard *linecard); void devlink_linecard_deactivate(struct devlink_linecard *linecard); -void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, - struct devlink *nested_devlink); +int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, + struct devlink *nested_devlink); int devl_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count, diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c index 36170f466878..9ff1813f88c5 100644 --- a/net/devlink/linecard.c +++ b/net/devlink/linecard.c @@ -17,7 +17,7 @@ struct devlink_linecard { const char *type; struct devlink_linecard_type *types; unsigned int types_count; - struct devlink *nested_devlink; + u32 rel_index; }; unsigned int devlink_linecard_index(struct devlink_linecard *linecard) @@ -112,10 +112,10 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, nla_nest_end(msg, attr); } - if (linecard->nested_devlink && - devlink_nl_put_nested_handle(msg, devlink_net(devlink), - linecard->nested_devlink, - DEVLINK_ATTR_NESTED_DEVLINK)) + if (devlink_rel_devlink_handle_put(msg, devlink, + linecard->rel_index, + DEVLINK_ATTR_NESTED_DEVLINK, + NULL)) goto nla_put_failure; genlmsg_end(msg, hdr); @@ -524,7 +524,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_set); void devlink_linecard_provision_clear(struct devlink_linecard *linecard) { mutex_lock(&linecard->state_lock); - WARN_ON(linecard->nested_devlink); linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; linecard->type = NULL; devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); @@ -543,7 +542,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear); void devlink_linecard_provision_fail(struct devlink_linecard *linecard) { mutex_lock(&linecard->state_lock); - WARN_ON(linecard->nested_devlink); linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED; devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); mutex_unlock(&linecard->state_lock); @@ -591,6 +589,27 @@ void devlink_linecard_deactivate(struct devlink_linecard *linecard) } EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); +static void devlink_linecard_rel_notify_cb(struct devlink *devlink, + u32 linecard_index) +{ + struct devlink_linecard *linecard; + + linecard = devlink_linecard_get_by_index(devlink, linecard_index); + if (!linecard) + return; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); +} + +static void devlink_linecard_rel_cleanup_cb(struct devlink *devlink, + u32 linecard_index, u32 rel_index) +{ + struct devlink_linecard *linecard; + + linecard = devlink_linecard_get_by_index(devlink, linecard_index); + if (linecard && linecard->rel_index == rel_index) + linecard->rel_index = 0; +} + /** * devlink_linecard_nested_dl_set - Attach/detach nested devlink * instance to linecard. @@ -598,12 +617,14 @@ EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); * @linecard: devlink linecard * @nested_devlink: devlink instance to attach or NULL to detach */ -void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, - struct devlink *nested_devlink) +int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, + struct devlink *nested_devlink) { - mutex_lock(&linecard->state_lock); - linecard->nested_devlink = nested_devlink; - devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); - mutex_unlock(&linecard->state_lock); + return devlink_rel_nested_in_add(&linecard->rel_index, + linecard->devlink->index, + linecard->index, + devlink_linecard_rel_notify_cb, + devlink_linecard_rel_cleanup_cb, + nested_devlink); } EXPORT_SYMBOL_GPL(devlink_linecard_nested_dl_set); From patchwork Wed Sep 13 07:12:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382533 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 0B7B119BB4 for ; Wed, 13 Sep 2023 07:13:07 +0000 (UTC) Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CEF1728 for ; Wed, 13 Sep 2023 00:13:06 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-500913779f5so11197774e87.2 for ; Wed, 13 Sep 2023 00:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589184; x=1695193984; 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=iBqvdbgG+OuMZGz3SuzPn/48+McVPXoSIJdlbfzUxxE=; b=Sy0g6DqXW9ITBZMZ5xEXqKdX7zeZnqP5wz2Ku/UlTmpEwfKcNuDoU5Yf9X4Yrl0TSh cGp1xtv7cRuJFfDgXVs1cu0b6Qmsxp3y8IiHYmywE6VkbgNTMlYrK4e0X3X9sASwK5tI 5P9kpjIhjd6DGiOleFHB2BJ5geKAjOCXCARWQ5pFrbxPACboxkAcAQFBRNhqyB3UwTa6 yQ1o9mHBb7gY8AmX4NxHGNumzK0kU0V9UV7yi/SIkcCqwleyi+7kaRsrALVAk9MFHfV+ CUlyagIkZAoKswc8TR2rFaC97BHw+KbYEYLNvwFJJ4e7lH+zo9uDDympz4Xr49QtBN+P dkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589184; x=1695193984; 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=iBqvdbgG+OuMZGz3SuzPn/48+McVPXoSIJdlbfzUxxE=; b=gmxDFkKvtW4RwHDPnJodBA3kuES5jaxXgAAJLe2rPzOBQch3TXNIW59sa/gfvJ0Pjw CGWRHZGyj+OJ4kXgCq0Q7Sw0kgTnKG8p9TFlg7/cpFbsYXW+Wjv1zgPZrnFRhw8Ffkw/ u1h7siAH1KwoFo5AYE0cmI1306aA5h02T3gYmttXfbpzJKooqfGFeriVNu46LpJch3eV Xre9p0AEEXRqV3ig+/e2Pvp6MxGceAFmy4me3EiDjDyILpospg6lBsQhjPgBHnsmqiBs c82S4Fmd99SkpKLRNd5HIrfqi5I0ces3dg+u7mHFAFQ91U+TlnOuHC2hoZL/UhgSw01E 4fBQ== X-Gm-Message-State: AOJu0Yx7Bm9itV0jU7NpXIhZxda+EI39qIoj9vMtYgLBv9lgMvoUGoyT kzDQwUgnYdcMao6wWCBqfCt/dtOV0kBqRwvKUao= X-Google-Smtp-Source: AGHT+IEk6QWgP7q/TNtYWnv7h9ZKSg/+NYrM1AFysI7TaaM9WPbTB8jkJtxNS5dvf1yH7z2pVkAMAA== X-Received: by 2002:a05:6512:3d17:b0:500:7f71:e46b with SMTP id d23-20020a0565123d1700b005007f71e46bmr1815498lfv.1.1694589184581; Wed, 13 Sep 2023 00:13:04 -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 u2-20020a7bc042000000b00401bbfb9b2bsm659107wmc.0.2023.09.13.00.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:13:04 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 11/12] devlink: introduce possibility to expose info about nested devlinks Date: Wed, 13 Sep 2023 09:12:42 +0200 Message-ID: <20230913071243.930265-12-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In mlx5, there is a devlink instance created for PCI device. Also, one separate devlink instance is created for auxiliary device that represents the netdev of uplink port. This relation is currently invisible to the devlink user. Benefit from the rel infrastructure and allow for nested devlink instance to set the relationship for the nested-in devlink instance. Note that there may be many nested instances, therefore use xarray to hold the list of rel_indexes for individual nested instances. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- include/net/devlink.h | 2 ++ net/devlink/core.c | 2 ++ net/devlink/dev.c | 49 +++++++++++++++++++++++++++++++++++++ net/devlink/devl_internal.h | 1 + 4 files changed, 54 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 0dfcd7d7fa18..fad8e36e3d98 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1921,6 +1921,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, void devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter); +int devl_nested_devlink_set(struct devlink *devlink, + struct devlink *nested_devlink); bool devlink_is_reload_failed(const struct devlink *devlink); void devlink_remote_reload_actions_performed(struct devlink *devlink, enum devlink_reload_limit limit, diff --git a/net/devlink/core.c b/net/devlink/core.c index 2a98ff9a2f6b..bcbbb952569f 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -430,6 +430,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC); xa_init_flags(&devlink->params, XA_FLAGS_ALLOC); xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); + xa_init_flags(&devlink->nested_rels, XA_FLAGS_ALLOC); write_pnet(&devlink->_net, net); INIT_LIST_HEAD(&devlink->rate_list); INIT_LIST_HEAD(&devlink->linecard_list); @@ -476,6 +477,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!xa_empty(&devlink->ports)); + xa_destroy(&devlink->nested_rels); xa_destroy(&devlink->snapshot_ids); xa_destroy(&devlink->params); xa_destroy(&devlink->ports); diff --git a/net/devlink/dev.c b/net/devlink/dev.c index 3ae26d9088ab..dc8039ca2b38 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -138,6 +138,23 @@ devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_r return -EMSGSIZE; } +static int devlink_nl_nested_fill(struct sk_buff *msg, struct devlink *devlink) +{ + unsigned long rel_index; + void *unused; + int err; + + xa_for_each(&devlink->nested_rels, rel_index, unused) { + err = devlink_rel_devlink_handle_put(msg, devlink, + rel_index, + DEVLINK_ATTR_NESTED_DEVLINK, + NULL); + if (err) + return err; + } + return 0; +} + static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, u32 seq, int flags) @@ -164,6 +181,10 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, goto dev_stats_nest_cancel; nla_nest_end(msg, dev_stats); + + if (devlink_nl_nested_fill(msg, devlink)) + goto nla_put_failure; + genlmsg_end(msg, hdr); return 0; @@ -230,6 +251,34 @@ int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one); } +static void devlink_rel_notify_cb(struct devlink *devlink, u32 obj_index) +{ + devlink_notify(devlink, DEVLINK_CMD_NEW); +} + +static void devlink_rel_cleanup_cb(struct devlink *devlink, u32 obj_index, + u32 rel_index) +{ + xa_erase(&devlink->nested_rels, rel_index); +} + +int devl_nested_devlink_set(struct devlink *devlink, + struct devlink *nested_devlink) +{ + u32 rel_index; + int err; + + err = devlink_rel_nested_in_add(&rel_index, devlink->index, 0, + devlink_rel_notify_cb, + devlink_rel_cleanup_cb, + nested_devlink); + if (err) + return err; + return xa_insert(&devlink->nested_rels, rel_index, + xa_mk_value(0), GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(devl_nested_devlink_set); + void devlink_notify_register(struct devlink *devlink) { devlink_notify(devlink, DEVLINK_CMD_NEW); diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 4cb534aff44d..741d1bf1bec8 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -58,6 +58,7 @@ struct devlink { refcount_t refcount; struct rcu_work rwork; struct devlink_rel *rel; + struct xarray nested_rels; char priv[] __aligned(NETDEV_ALIGN); }; From patchwork Wed Sep 13 07:12:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13382534 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 621BC19BB4 for ; Wed, 13 Sep 2023 07:13:08 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A138C1728 for ; Wed, 13 Sep 2023 00:13:07 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-401d10e3e54so70078035e9.2 for ; Wed, 13 Sep 2023 00:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1694589186; x=1695193986; 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=TSueh9Yv9KLqh0yGW2vN2PuFR/O304sW84zrnLv9qZc=; b=BworEQEKs+VLTezeoJwXMEFi0nHn0wWlwMQUv1TSt6TqN/iUgmlmcbHaiPRuoQ/GZs SOTvY9WkGCTjYtcJIhtQVnKrRH8RSxsV0LK/RILpoop1P4mUoSZW9ffTm58Uiakaq04B 6BWPf7isdpH2py/LIGH+0ZRXvepVqBcCskFsXsDCNEUhhWH69DZ/NOVUma0jEESce3yO AhBOk1Kyy3+6GUu5AQ2oDy1svSAgq82x13mlXb3KhwNLhmn4fD6jPgMiBHHUyB+8m/p8 oxqHGqZszYyzvh1tlk3AMIoxxNdmNVG4CHcMWWnJk6cSpgnmCiSaZCTjfLYxfee4sKDM Bocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694589186; x=1695193986; 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=TSueh9Yv9KLqh0yGW2vN2PuFR/O304sW84zrnLv9qZc=; b=qLwdu1dpuu6qwsbHtDfQEexafUjsHRoN/rpSE5d7PFA7Myj4PKYEADh66SJmrKn9Wa BrdRr9zBmKryL0q35DPSlEdK/mMANV01Vl9flOxP5fOzp1LwPoP0Rht6hEml5f2+6mfI yLnFvBLcAt9g0qCJqxYl2vzodGHZ901ijiUPHixrT77mwmUNkeI2nvkOurB4b/Pm0juh MqGMv4uBY+Jl/PSY8mzJSmV/RDaCczyWr53JvBT++EmWI+hg9eNaxOwLoYzcYEhW9xnb zSlZMi9MYhD9lIDgACOR2hM0/66XyLnqk4jFSR8ZNumCKxMi6ENycwiKOSyyW2rZNOVt 2Kmg== X-Gm-Message-State: AOJu0YzbhHVjTdqOJk3GJAm30Tri9p6OtmwAXUGSLUGbA67LSsMsS5hq mcHa/a3BDYwsMkoqLa4t5LRNBsh3NxUllWX3zuk= X-Google-Smtp-Source: AGHT+IG4DmhRepIORlDwJzUudoZ9xr485y2+6khn0CpS7JRGEFsIktAkKIJ1hCMaRZGMGVzf6wkRng== X-Received: by 2002:a1c:7407:0:b0:401:d803:6241 with SMTP id p7-20020a1c7407000000b00401d8036241mr1251338wmc.21.1694589186204; Wed, 13 Sep 2023 00:13:06 -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 x20-20020a05600c2a5400b003fe601a7d46sm1099400wme.45.2023.09.13.00.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:13:05 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, idosch@nvidia.com, petrm@nvidia.com, jacob.e.keller@intel.com, moshe@nvidia.com, shayd@nvidia.com, saeedm@nvidia.com, horms@kernel.org Subject: [patch net-next v2 12/12] net/mlx5e: Set en auxiliary devlink instance as nested Date: Wed, 13 Sep 2023 09:12:43 +0200 Message-ID: <20230913071243.930265-13-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913071243.930265-1-jiri@resnulli.us> References: <20230913071243.930265-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Benefit from the previous commit introducing exposure of devlink instances relationship and set the nested instance for en auxiliary device. Signed-off-by: Jiri Pirko --- v1->v2: - new patch --- drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c index c6b6e290fd79..0b1ac6e5c890 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c @@ -12,11 +12,19 @@ struct mlx5e_dev *mlx5e_create_devlink(struct device *dev, { struct mlx5e_dev *mlx5e_dev; struct devlink *devlink; + int err; devlink = devlink_alloc_ns(&mlx5e_devlink_ops, sizeof(*mlx5e_dev), devlink_net(priv_to_devlink(mdev)), dev); if (!devlink) return ERR_PTR(-ENOMEM); + + err = devl_nested_devlink_set(priv_to_devlink(mdev), devlink); + if (err) { + devlink_free(devlink); + return ERR_PTR(err); + } + devlink_register(devlink); return devlink_priv(devlink); }