From patchwork Thu Feb 9 15:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134807 X-Patchwork-Delegate: kuba@kernel.org 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 611E1C61DA4 for ; Thu, 9 Feb 2023 15:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjBIPn7 (ORCPT ); Thu, 9 Feb 2023 10:43:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbjBIPnq (ORCPT ); Thu, 9 Feb 2023 10:43:46 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D5764D83 for ; Thu, 9 Feb 2023 07:43:18 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id gr7so7598320ejb.5 for ; Thu, 09 Feb 2023 07:43:18 -0800 (PST) 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:subject:date :message-id:reply-to; bh=P4dqEUDE9TT3v5WYQVTEABMK+I4AxBfn/2LZe716e9w=; b=WkHLKTG3o3wgpHqoPvb3xYo0SakssQJu9FkhE03xCr2PL7gr6xx1uB9WRkVYZH38ev 05f+Bepuys6dCZZi5ZHU/W2MGmWuoMwKmbftO7i288o9S0VQaS7UzAvy+8Z0d05/nKT5 9GCSjswHlDUfmijuLd8rTHSpvez0tK24rkRx4bmBfF/43CNx9cdVomaK8zLV5QR6ZYk8 m/BerYjnjg/Z9otkuvncib/kA0L+rwVkaRHMKuzN3RUr+K5mfXjcpBC2dJ1ONcQaJ/ir NItiGMOcrcSwStbsiKLWQCndJlvXgL6EyBPOYR+88xb6YJfOTQc+zQCAFqiiUhb2jLDr Hjgw== 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 :subject:date:message-id:reply-to; bh=P4dqEUDE9TT3v5WYQVTEABMK+I4AxBfn/2LZe716e9w=; b=YVa/wHMufflMozCTwyKTsinxh2ZCcIfzgiBwJY+yaQKTFQWCncAQUA+ex+MCn/zlt8 azB+Xnr/v6MXOABwkPZNqYturU6gbQraZ4kkH1lCd9OOpM98ALHxx2vplb37BQGD2RNh J0J82WTgkMtNcFr+Bi2SBdFhyW6GEdC+49/pXk152sfW21vo8OVmS06r+fwwIjTUxQyK fJQurCqGG8K8+jnEsGYeDICXXt7vzBKlUv/VVdTslM9mfte4AqTKpDw9MQgd96j6HQVO GDw3FRY/mPUYOIgftQcMorVFvoTMGzD/xRp0dRVooKc8mYPwSB2OPr07dcqlqZkNmK66 pqUQ== X-Gm-Message-State: AO0yUKU11SaFa/Hd6pfVNEsVF8F7xxAaR3CT42Dzd7xahHi+I9JMTCly QyRRurhpUXZVzLxI/ZAB2/cxQSLJ1NE+BEOz2KE= X-Google-Smtp-Source: AK7set9kkL6zJ0uBQDXCTSin4Hga5IFG4fyWQPM+SCsu2Voa/KzovrTD0V+KCcaBXdJUYKsAt/C5Jg== X-Received: by 2002:a17:906:1ec8:b0:888:a72f:1599 with SMTP id m8-20020a1709061ec800b00888a72f1599mr12607045ejj.11.1675957393190; Thu, 09 Feb 2023 07:43:13 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id k2-20020a1709063e0200b00878b89075adsm1029887eji.51.2023.02.09.07.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:12 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 1/7] devlink: don't use strcpy() to copy param value Date: Thu, 9 Feb 2023 16:43:02 +0100 Message-Id: <20230209154308.2984602-2-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko No need to treat string params any different comparing to other types. Rely on the struct assign to copy the whole struct, including the string. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- net/devlink/leftover.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 9d6373603340..6225651e34b9 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -4388,10 +4388,7 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink, return -EOPNOTSUPP; if (cmode == DEVLINK_PARAM_CMODE_DRIVERINIT) { - if (param->type == DEVLINK_PARAM_TYPE_STRING) - strcpy(param_item->driverinit_value.vstr, value.vstr); - else - param_item->driverinit_value = value; + param_item->driverinit_value = value; param_item->driverinit_value_valid = true; } else { if (!param->set) @@ -9652,10 +9649,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT))) return -EOPNOTSUPP; - if (param_item->param->type == DEVLINK_PARAM_TYPE_STRING) - strcpy(init_val->vstr, param_item->driverinit_value.vstr); - else - *init_val = param_item->driverinit_value; + *init_val = param_item->driverinit_value; return 0; } @@ -9686,10 +9680,7 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT))) return; - if (param_item->param->type == DEVLINK_PARAM_TYPE_STRING) - strcpy(param_item->driverinit_value.vstr, init_val.vstr); - else - param_item->driverinit_value = init_val; + param_item->driverinit_value = init_val; param_item->driverinit_value_valid = true; devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW); From patchwork Thu Feb 9 15:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134809 X-Patchwork-Delegate: kuba@kernel.org 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 49E43C61DA4 for ; Thu, 9 Feb 2023 15:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbjBIPoN (ORCPT ); Thu, 9 Feb 2023 10:44:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjBIPny (ORCPT ); Thu, 9 Feb 2023 10:43:54 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A6E65661 for ; Thu, 9 Feb 2023 07:43:31 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id rp23so7557458ejb.7 for ; Thu, 09 Feb 2023 07:43:30 -0800 (PST) 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:subject:date :message-id:reply-to; bh=I02J60Y4R+ohFSpmLQ7WdxxzP6KuaX6SRH/Y+gZeSYc=; b=cMmmJmqLCOzAF3n5n5xR7wSi8GSbs3kS4clZlhdSXNEdWzDPbvpLJzUI9Q2raIMUk8 glzZCW79TvcM8AGCVeNbmCAOh/aeMMemRnFqz2QKi/3n8LALm+kAqvwfiaT7mYOs+tyv pD7p1ymoT6Z9upxtqXqHEWngWrVVfAWvpgsU+WjVqZZhuiW9KHnb/KR7H61yVBV4eY6u WSbHYvYjN38VQI6lVxFfttbe590wbBribDEpGMg9V0K2bwezXUBvew7rdoxB2Ja6lbOh 6n8tgXq1oF8MjnNYFe1m6GAXnzcp9AfeucLf40acfs0Tl3fQs5RmRmHHlm+hFdm8fUVQ SuTQ== 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 :subject:date:message-id:reply-to; bh=I02J60Y4R+ohFSpmLQ7WdxxzP6KuaX6SRH/Y+gZeSYc=; b=wUMiKSi+mewD6E77V47WSIMeEaP+CecNFvkNqVS5IeYrOMvPZjNfiqcao+YH58Tui5 k677WrHI+lFK8hQigQr64vuPxDb+AQvtaMv8uSdxDiBFGwAJ6VNUSxi1ntjBfiSmmIhi C7OJ70twybfGP2cihz3xIV05LRQcc1nabwVZBj4hVFYz9/OkD3R49aTaWmE0j50WxSEH FNnf8nb8f4kzaQArzpigS3JaI8l37uWUslb/CHS3iOTMvK+HI6ZmNLkB+xKITkpecydU 0D+QEwWWsxIKhyCbG+75UPCzEHFeV5UobLwiTj8Q0GPLcKNc+qpUFOichEwDToRic13K f6iw== X-Gm-Message-State: AO0yUKWaRAQKeKyzzPJRneqzG7Q0Q0j3jEYDqc+FIAoFyPj9JmAWSTgf MlSpZNCQVKYTZCLJCZYLZb86kLWTMz6e0CC+B1o= X-Google-Smtp-Source: AK7set8ftczx8GqRUnkL01cnAKwaUGpq25BuVARC0atnPYfoKA3h/7/VHOwoHHAnMKhH8UNBBa97oA== X-Received: by 2002:a17:906:6557:b0:885:d02f:d4ad with SMTP id u23-20020a170906655700b00885d02fd4admr13023631ejn.43.1675957395748; Thu, 09 Feb 2023 07:43:15 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id p5-20020a170906b20500b0087276f66c6asm1021748ejz.115.2023.02.09.07.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:14 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 2/7] devlink: make sure driver does not read updated driverinit param before reload Date: Thu, 9 Feb 2023 16:43:03 +0100 Message-Id: <20230209154308.2984602-3-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The driverinit param purpose is to serve the driver during init/reload time to provide a value, either default or set by user. Make sure that driver does not read value updated by user before the reload is performed. Hold the new value in a separate struct and switch it during reload. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- include/net/devlink.h | 4 ++++ net/devlink/dev.c | 2 ++ net/devlink/devl_internal.h | 3 +++ net/devlink/leftover.c | 26 ++++++++++++++++++++++---- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 2e85a5970a32..8ed960345f37 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -489,6 +489,10 @@ struct devlink_param_item { const struct devlink_param *param; union devlink_param_value driverinit_value; bool driverinit_value_valid; + union devlink_param_value driverinit_value_new; /* Not reachable + * until reload. + */ + bool driverinit_value_new_valid; }; enum devlink_param_generic_id { diff --git a/net/devlink/dev.c b/net/devlink/dev.c index 78d824eda5ec..32e5d1b28a47 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -369,6 +369,8 @@ int devlink_reload(struct devlink *devlink, struct net *dest_net, if (dest_net && !net_eq(dest_net, curr_net)) devlink_reload_netns_change(devlink, curr_net, dest_net); + devlink_params_driverinit_load_new(devlink); + err = devlink->ops->reload_up(devlink, action, limit, actions_performed, extack); devlink_reload_failed_set(devlink, !!err); if (err) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 941174e157d4..5c117e8d4377 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -189,6 +189,9 @@ static inline bool devlink_reload_supported(const struct devlink_ops *ops) return ops->reload_down && ops->reload_up; } +/* Params */ +void devlink_params_driverinit_load_new(struct devlink *devlink); + /* Resources */ struct devlink_resource; int devlink_resources_validate(struct devlink *devlink, diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 6225651e34b9..6c4c95c658c7 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -4098,9 +4098,12 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink, if (!devlink_param_cmode_is_supported(param, i)) continue; if (i == DEVLINK_PARAM_CMODE_DRIVERINIT) { - if (!param_item->driverinit_value_valid) + if (param_item->driverinit_value_new_valid) + param_value[i] = param_item->driverinit_value_new; + else if (param_item->driverinit_value_valid) + param_value[i] = param_item->driverinit_value; + else return -EOPNOTSUPP; - param_value[i] = param_item->driverinit_value; } else { ctx.cmode = i; err = devlink_param_get(devlink, param, &ctx); @@ -4388,8 +4391,8 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink, return -EOPNOTSUPP; if (cmode == DEVLINK_PARAM_CMODE_DRIVERINIT) { - param_item->driverinit_value = value; - param_item->driverinit_value_valid = true; + param_item->driverinit_value_new = value; + param_item->driverinit_value_new_valid = true; } else { if (!param->set) return -EOPNOTSUPP; @@ -9687,6 +9690,21 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, } EXPORT_SYMBOL_GPL(devl_param_driverinit_value_set); +void devlink_params_driverinit_load_new(struct devlink *devlink) +{ + struct devlink_param_item *param_item; + + list_for_each_entry(param_item, &devlink->param_list, list) { + if (!devlink_param_cmode_is_supported(param_item->param, + DEVLINK_PARAM_CMODE_DRIVERINIT) || + !param_item->driverinit_value_new_valid) + continue; + param_item->driverinit_value = param_item->driverinit_value_new; + param_item->driverinit_value_valid = true; + param_item->driverinit_value_new_valid = false; + } +} + /** * devl_param_value_changed - notify devlink on a parameter's value * change. Should be called by the driver From patchwork Thu Feb 9 15:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134810 X-Patchwork-Delegate: kuba@kernel.org 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 0BDCFC636D6 for ; Thu, 9 Feb 2023 15:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbjBIPoN (ORCPT ); Thu, 9 Feb 2023 10:44:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231414AbjBIPnz (ORCPT ); Thu, 9 Feb 2023 10:43:55 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BA98611C9 for ; Thu, 9 Feb 2023 07:43:31 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id dr8so7506284ejc.12 for ; Thu, 09 Feb 2023 07:43:31 -0800 (PST) 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:subject:date :message-id:reply-to; bh=2j7izrLQS/3wwxbZ0AOP8xYWibSrF399ZiXullspJXg=; b=fOyZFwuh0Q9wYRuvRjRGvjqKKAEy8ZfmkbQtYvJSprMSvncXEBdLFKDJlXK1UgjSBv XqK0+4VFKyT2oqwppnZzVfs546Z7R1h7WbN4bjY+CFdrXCyrfPoVM6f9/1E43qQW9tiU JMM0hCUKBRhWDzxhanmzoCts8siWRDaySt+fldbMCOtH3ZnFL49dc4jcv+DUgNtdpDRR 59yneU2wdnk7udlHaCzCuMmpc3mdg6buyCKnIgVqQHlb32gwnWvlamHAcwTr2emmdSPy 1PGXk1SkJR7eUcF+lKYBUw9sMhci5p05K3FL1CDWOVBjl0cnZaMg7clq1EO+9SFY7qG0 ddJQ== 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 :subject:date:message-id:reply-to; bh=2j7izrLQS/3wwxbZ0AOP8xYWibSrF399ZiXullspJXg=; b=B6dKpg0+eduMiOtC2kQfnKwX8grd3Rt46jUzeZCY3pYsbaDgc8Z7nELECCgdxi4Fno DBJPtL4p3ARwrGmchy6Eb2+NLWPHxtE8R48IkOmwYoUPyxleCh+/iF3VSEQIgL/dsFUU AD5TSciN7sQ+59S4mDpm2wVFuR1n3pflU7KJgtbBVMHdEc+Ifxx+g/27gFHrQCUz9/Ip qC5nQusivTpPI+OHeX9flcJyTIH7ef2Eg0eMlOcqYIZPm8r9Bv9PV00MZ1EeZYnRGB4S EcgmXC6jYv9XMppW1U5WdHjSZbcwkdiOq4trHb+A52yje0tGNGy631slMpDlZpaEAH24 khYQ== X-Gm-Message-State: AO0yUKUa7cu9r9QTNbBfZs8Xvi3prknwVVJq8z1XsFl//25s3L5sofr0 /ScaC3sdV8XfSNAuWjcVZvza1H6ByVjU55H5ld4= X-Google-Smtp-Source: AK7set8zf1kKTgG+Mgwvh1m0gpc/FjMS7Nligm7AXZ2jF4nqhJhQChMT75oBGyfxERq/aldIIdOpnw== X-Received: by 2002:a17:907:3f93:b0:82e:a57b:cc9b with SMTP id hr19-20020a1709073f9300b0082ea57bcc9bmr9501611ejc.24.1675957398298; Thu, 09 Feb 2023 07:43:18 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id a23-20020a1709063a5700b0087bcda2b07bsm983310ejf.202.2023.02.09.07.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:17 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 3/7] devlink: fix the name of value arg of devl_param_driverinit_value_get() Date: Thu, 9 Feb 2023 16:43:04 +0100 Message-Id: <20230209154308.2984602-4-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Probably due to copy-paste error, the name of the arg is "init_val" which is misleading, as the pointer is used to point to struct where to store the current value. Rename it to "val" and change the arg comment a bit on the way. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- include/net/devlink.h | 2 +- net/devlink/leftover.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 8ed960345f37..6a942e70e451 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1784,7 +1784,7 @@ void devlink_params_unregister(struct devlink *devlink, const struct devlink_param *params, size_t params_count); int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, - union devlink_param_value *init_val); + union devlink_param_value *val); void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, union devlink_param_value init_val); void devl_param_value_changed(struct devlink *devlink, u32 param_id); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 6c4c95c658c7..1db45aeff764 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -9626,13 +9626,14 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister); * * @devlink: devlink * @param_id: parameter ID - * @init_val: value of parameter in driverinit configuration mode + * @val: pointer to store the value of parameter in driverinit + * configuration mode * * This function should be used by the driver to get driverinit * configuration for initialization after reload command. */ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, - union devlink_param_value *init_val) + union devlink_param_value *val) { struct devlink_param_item *param_item; @@ -9652,7 +9653,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT))) return -EOPNOTSUPP; - *init_val = param_item->driverinit_value; + *val = param_item->driverinit_value; return 0; } From patchwork Thu Feb 9 15:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134811 X-Patchwork-Delegate: kuba@kernel.org 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 DE6FBC61DA4 for ; Thu, 9 Feb 2023 15:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231630AbjBIPo0 (ORCPT ); Thu, 9 Feb 2023 10:44:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231658AbjBIPoF (ORCPT ); Thu, 9 Feb 2023 10:44:05 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A22A53E082 for ; Thu, 9 Feb 2023 07:43:42 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id sa10so7543590ejc.9 for ; Thu, 09 Feb 2023 07:43:42 -0800 (PST) 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:subject:date :message-id:reply-to; bh=Php+pwcOHz0uoBaLh2xP3WNJg/chh4cP4sGUxovIVz4=; b=kKy/Vf9H0PEKCnG2pk5ryKxY1Bv4aqnm5fupHxc5soxgtA3NrOZDtzeIt6zMs2o+J5 Jib77Sg+Hym1Tshwqiec/NgHv+HiJ1Jbx3h8YUANg9BdStfa8idhQoFNxKmk5ZUq9qTX 1gjiGuJUKDxs7XZWjIJKv78sTh0aornpsygusNS91d0zKpSO6NneAgxJIFpX8vVF6YGj g0r1wB+Qiv1ca/P0P5hiifhuOCRmK9p1CFCZuCgNK3BZ0ZW62FEPkDiULR3BTy3ycq7x eMgj0Gic2pbzhA7qgjgz6sN/T9yymq75ZlVPecTv1RU+UJ7CPoET69RGay58t7zWalA+ 4pKw== 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 :subject:date:message-id:reply-to; bh=Php+pwcOHz0uoBaLh2xP3WNJg/chh4cP4sGUxovIVz4=; b=ztS/1ys3b+9FLXQM9Tj9+6bMKz8pJo1yKUB3QDegEP/BUpdCxssSnSTQKKG15nNH3l 3Pq0dzIgAQTs9i4U8kPauVZ3LisjxORQB/PgEvlDsK5assSxtzglfYKODj5C8LQyr/Ky RXNyf1XH2wGjo6QU1XHnKfqgsSxuUPDmQzfec2eBMrti0HKlyzhdNc4f4EIacBTmAl+7 VBPf1+k6sDyLF3rKyTkQ5yZTNkzgf8iyh3SQRwuTgurZDvk/4JGr8yq2AkijHNa75gSR 43NJI9lRhY0soaIcEIVBN2AY7+cl81ZMC0iO5b9qChSW9Qt8GAkf0qsVqeP0uev9gm7J o++A== X-Gm-Message-State: AO0yUKXdr4y4ohCNHtONW0r28jnIfSsHKL0ZJ4RQ9iBexP1mgM9AjjGM xV5I4fyCcJ488EHaqWhXWjok2Lnr/acDNCkLRSI= X-Google-Smtp-Source: AK7set+F9RfLfdG9KxrqCWdEG+SOYw3OQPbcLMeP5SW40B4bMcgmWkDQigGcllcT+2NquUuls0tNYg== X-Received: by 2002:a17:906:5207:b0:88e:682e:3a9e with SMTP id g7-20020a170906520700b0088e682e3a9emr11927664ejm.61.1675957400820; Thu, 09 Feb 2023 07:43:20 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id x27-20020a170906135b00b007ae32daf4b9sm1010499ejb.106.2023.02.09.07.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:20 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 4/7] devlink: use xa_for_each_start() helper in devlink_nl_cmd_port_get_dump_one() Date: Thu, 9 Feb 2023 16:43:05 +0100 Message-Id: <20230209154308.2984602-5-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko As xarray has an iterator helper that allows to start from specified index, use this directly and avoid repeated iteration from 0. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- net/devlink/leftover.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 1db45aeff764..bbace07ff063 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -1111,24 +1111,18 @@ devlink_nl_cmd_port_get_dump_one(struct sk_buff *msg, struct devlink *devlink, struct devlink_nl_dump_state *state = devlink_dump_state(cb); struct devlink_port *devlink_port; unsigned long port_index; - int idx = 0; int err = 0; - xa_for_each(&devlink->ports, port_index, devlink_port) { - if (idx < state->idx) { - idx++; - continue; - } + xa_for_each_start(&devlink->ports, port_index, devlink_port, state->idx) { err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->extack); if (err) { - state->idx = idx; + state->idx = port_index; break; } - idx++; } return err; From patchwork Thu Feb 9 15:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134812 X-Patchwork-Delegate: kuba@kernel.org 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 0DB89C61DA4 for ; Thu, 9 Feb 2023 15:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbjBIPog (ORCPT ); Thu, 9 Feb 2023 10:44:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbjBIPoL (ORCPT ); Thu, 9 Feb 2023 10:44:11 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C40D46466B for ; Thu, 9 Feb 2023 07:43:52 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id c26so2796805ejz.10 for ; Thu, 09 Feb 2023 07:43:52 -0800 (PST) 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:subject:date :message-id:reply-to; bh=SBmRGo4Xdaf28uxityOhoQZN5pyy8JJpAUrk4r3fGIM=; b=pq4RWh4/SBcBDJ4zuB/vIW07ue2uENFloksxBZdJfIEHqKTxRmWn7D2G8C7YbPBmxI wV3VvbaDT9WaHF1tnIerPfC6BdEiEMgsNlKrhC845Os2JKTtt5IvXARL4T/iKSd0sB4R tVRMxmXJ59QyeTqQAbOS6JsMD8ej2CVogfQZJpK5OZTcMmXcdweZR20Tg83Lc/w0xYFq sToVppS15zUXm/WC7tgmLaTItt8R3IKXyZeWUSUW1nGhl5uDLTHiOxnPULx+wAhXEU6g TCfLhreJOfPkeJ8qI5F82WqXbj5SEYcoOhiAM4uCsOmJHfQBP9pF6gt1XKN4toTWhcvL T9aQ== 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 :subject:date:message-id:reply-to; bh=SBmRGo4Xdaf28uxityOhoQZN5pyy8JJpAUrk4r3fGIM=; b=KwQzXFrhp6l4fk0gHpXwC7s3yg/idCR6qlwEUmjK5C9l2Om/oqajYbG3l8+LDtdotA lwOa/a/N6F+4Z1kIcR1KaB3q4gFCDaw01rBJOUNCmV+QDnzR/G4t4veYOLXL2tkSsgxC BF6coaFZpLP0TP+g6+TGxHDKqm7C8klu8FwNfrqFqhWeza10+6BhQtgr6DF2zjJ8RPSg t/OrzrBmI0ChVb0OkSMSD0PMwc9CUBkwKqwcjvrzg/sSQr76gntj9LuoDHb6qxhpkRLJ egx/Bx1bvo0vzZtg89e/GTvNBUmx2DhUxQwY6z3oSFse9mzcu5dEnLGeeOtUNmj+KkWP q1mA== X-Gm-Message-State: AO0yUKUfSm/oG+ysYqgUx5lnjIi5O/HfUYMZLJSil6BikAkWX/P+Bl76 o5Pt5TOfdB2sy5iK3k4j7DjVuqmWdVsJw8Z/AjQ= X-Google-Smtp-Source: AK7set/eP/FriKdIMvECy6D0RyFEf4Ajh0ze1UPfI6wKNQR3L/KrG/iAxl9VHGuYBlNVScNYmkYhlg== X-Received: by 2002:a17:906:b255:b0:879:6abe:915e with SMTP id ce21-20020a170906b25500b008796abe915emr14243425ejb.69.1675957403424; Thu, 09 Feb 2023 07:43:23 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id z10-20020a17090674ca00b00889db195470sm1019400ejl.82.2023.02.09.07.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:22 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 5/7] devlink: convert param list to xarray Date: Thu, 9 Feb 2023 16:43:06 +0100 Message-Id: <20230209154308.2984602-6-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Loose the linked list for params and use xarray instead. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- net/devlink/core.c | 4 +-- net/devlink/devl_internal.h | 2 +- net/devlink/leftover.c | 72 ++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index aeffd1b8206d..2d66706d4b36 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -212,6 +212,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, devlink->dev = dev; 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); write_pnet(&devlink->_net, net); INIT_LIST_HEAD(&devlink->rate_list); @@ -219,7 +220,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, INIT_LIST_HEAD(&devlink->sb_list); INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list); INIT_LIST_HEAD(&devlink->resource_list); - INIT_LIST_HEAD(&devlink->param_list); INIT_LIST_HEAD(&devlink->region_list); INIT_LIST_HEAD(&devlink->reporter_list); INIT_LIST_HEAD(&devlink->trap_list); @@ -255,7 +255,6 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->trap_list)); WARN_ON(!list_empty(&devlink->reporter_list)); WARN_ON(!list_empty(&devlink->region_list)); - WARN_ON(!list_empty(&devlink->param_list)); WARN_ON(!list_empty(&devlink->resource_list)); WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); @@ -264,6 +263,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!xa_empty(&devlink->ports)); xa_destroy(&devlink->snapshot_ids); + xa_destroy(&devlink->params); xa_destroy(&devlink->ports); WARN_ON_ONCE(unregister_netdevice_notifier_net(devlink_net(devlink), diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 5c117e8d4377..2f4820e40d27 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -29,7 +29,7 @@ struct devlink { struct list_head sb_list; struct list_head dpipe_table_list; struct list_head resource_list; - struct list_head param_list; + struct xarray params; struct list_head region_list; struct list_head reporter_list; struct devlink_dpipe_headers *dpipe_headers; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index bbace07ff063..805c2b7ff468 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -3954,26 +3954,22 @@ static int devlink_param_driver_verify(const struct devlink_param *param) } static struct devlink_param_item * -devlink_param_find_by_name(struct list_head *param_list, - const char *param_name) +devlink_param_find_by_name(struct xarray *params, const char *param_name) { struct devlink_param_item *param_item; + unsigned long param_id; - list_for_each_entry(param_item, param_list, list) + xa_for_each(params, param_id, param_item) { if (!strcmp(param_item->param->name, param_name)) return param_item; + } return NULL; } static struct devlink_param_item * -devlink_param_find_by_id(struct list_head *param_list, u32 param_id) +devlink_param_find_by_id(struct xarray *params, u32 param_id) { - struct devlink_param_item *param_item; - - list_for_each_entry(param_item, param_list, list) - if (param_item->param->id == param_id) - return param_item; - return NULL; + return xa_load(params, param_id); } static bool @@ -4202,14 +4198,10 @@ devlink_nl_cmd_param_get_dump_one(struct sk_buff *msg, struct devlink *devlink, { struct devlink_nl_dump_state *state = devlink_dump_state(cb); struct devlink_param_item *param_item; - int idx = 0; + unsigned long param_id; int err = 0; - list_for_each_entry(param_item, &devlink->param_list, list) { - if (idx < state->idx) { - idx++; - continue; - } + xa_for_each_start(&devlink->params, param_id, param_item, state->idx) { err = devlink_nl_param_fill(msg, devlink, 0, param_item, DEVLINK_CMD_PARAM_GET, NETLINK_CB(cb->skb).portid, @@ -4218,10 +4210,9 @@ devlink_nl_cmd_param_get_dump_one(struct sk_buff *msg, struct devlink *devlink, if (err == -EOPNOTSUPP) { err = 0; } else if (err) { - state->idx = idx; + state->idx = param_id; break; } - idx++; } return err; @@ -4307,8 +4298,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param, } static struct devlink_param_item * -devlink_param_get_from_info(struct list_head *param_list, - struct genl_info *info) +devlink_param_get_from_info(struct xarray *params, struct genl_info *info) { char *param_name; @@ -4316,7 +4306,7 @@ devlink_param_get_from_info(struct list_head *param_list, return NULL; param_name = nla_data(info->attrs[DEVLINK_ATTR_PARAM_NAME]); - return devlink_param_find_by_name(param_list, param_name); + return devlink_param_find_by_name(params, param_name); } static int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, @@ -4327,7 +4317,7 @@ static int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, struct sk_buff *msg; int err; - param_item = devlink_param_get_from_info(&devlink->param_list, info); + param_item = devlink_param_get_from_info(&devlink->params, info); if (!param_item) return -EINVAL; @@ -4348,7 +4338,7 @@ static int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink, unsigned int port_index, - struct list_head *param_list, + struct xarray *params, struct genl_info *info, enum devlink_command cmd) { @@ -4360,7 +4350,7 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink, union devlink_param_value value; int err = 0; - param_item = devlink_param_get_from_info(param_list, info); + param_item = devlink_param_get_from_info(params, info); if (!param_item) return -EINVAL; param = param_item->param; @@ -4406,7 +4396,7 @@ static int devlink_nl_cmd_param_set_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; - return __devlink_nl_cmd_param_set_doit(devlink, 0, &devlink->param_list, + return __devlink_nl_cmd_param_set_doit(devlink, 0, &devlink->params, info, DEVLINK_CMD_PARAM_NEW); } @@ -8038,6 +8028,7 @@ void devlink_notify_register(struct devlink *devlink) struct devlink_rate *rate_node; struct devlink_region *region; unsigned long port_index; + unsigned long param_id; devlink_notify(devlink, DEVLINK_CMD_NEW); list_for_each_entry(linecard, &devlink->linecard_list, list) @@ -8063,7 +8054,7 @@ void devlink_notify_register(struct devlink *devlink) list_for_each_entry(region, &devlink->region_list, list) devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW); - list_for_each_entry(param_item, &devlink->param_list, list) + xa_for_each(&devlink->params, param_id, param_item) devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW); } @@ -8078,8 +8069,9 @@ void devlink_notify_unregister(struct devlink *devlink) struct devlink_rate *rate_node; struct devlink_region *region; unsigned long port_index; + unsigned long param_id; - list_for_each_entry_reverse(param_item, &devlink->param_list, list) + xa_for_each(&devlink->params, param_id, param_item) devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_DEL); @@ -9502,9 +9494,10 @@ static int devlink_param_register(struct devlink *devlink, const struct devlink_param *param) { struct devlink_param_item *param_item; + int err; WARN_ON(devlink_param_verify(param)); - WARN_ON(devlink_param_find_by_name(&devlink->param_list, param->name)); + WARN_ON(devlink_param_find_by_name(&devlink->params, param->name)); if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT)) WARN_ON(param->get || param->set); @@ -9517,9 +9510,16 @@ static int devlink_param_register(struct devlink *devlink, param_item->param = param; - list_add_tail(¶m_item->list, &devlink->param_list); + err = xa_insert(&devlink->params, param->id, param_item, GFP_KERNEL); + if (err) + goto err_xa_insert; + devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW); return 0; + +err_xa_insert: + kfree(param_item); + return err; } static void devlink_param_unregister(struct devlink *devlink, @@ -9527,12 +9527,11 @@ static void devlink_param_unregister(struct devlink *devlink, { struct devlink_param_item *param_item; - param_item = - devlink_param_find_by_name(&devlink->param_list, param->name); + param_item = devlink_param_find_by_id(&devlink->params, param->id); if (WARN_ON(!param_item)) return; devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_DEL); - list_del(¶m_item->list); + xa_erase(&devlink->params, param->id); kfree(param_item); } @@ -9636,7 +9635,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, if (WARN_ON(!devlink_reload_supported(devlink->ops))) return -EOPNOTSUPP; - param_item = devlink_param_find_by_id(&devlink->param_list, param_id); + param_item = devlink_param_find_by_id(&devlink->params, param_id); if (!param_item) return -EINVAL; @@ -9670,7 +9669,7 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, { struct devlink_param_item *param_item; - param_item = devlink_param_find_by_id(&devlink->param_list, param_id); + param_item = devlink_param_find_by_id(&devlink->params, param_id); if (WARN_ON(!param_item)) return; @@ -9688,8 +9687,9 @@ EXPORT_SYMBOL_GPL(devl_param_driverinit_value_set); void devlink_params_driverinit_load_new(struct devlink *devlink) { struct devlink_param_item *param_item; + unsigned long param_id; - list_for_each_entry(param_item, &devlink->param_list, list) { + xa_for_each(&devlink->params, param_id, param_item) { if (!devlink_param_cmode_is_supported(param_item->param, DEVLINK_PARAM_CMODE_DRIVERINIT) || !param_item->driverinit_value_new_valid) @@ -9716,7 +9716,7 @@ void devl_param_value_changed(struct devlink *devlink, u32 param_id) { struct devlink_param_item *param_item; - param_item = devlink_param_find_by_id(&devlink->param_list, param_id); + param_item = devlink_param_find_by_id(&devlink->params, param_id); WARN_ON(!param_item); devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW); From patchwork Thu Feb 9 15:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134813 X-Patchwork-Delegate: kuba@kernel.org 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 EBCD3C61DA4 for ; Thu, 9 Feb 2023 15:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231327AbjBIPom (ORCPT ); Thu, 9 Feb 2023 10:44:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231679AbjBIPoS (ORCPT ); Thu, 9 Feb 2023 10:44:18 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A41F65660 for ; Thu, 9 Feb 2023 07:43:58 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id dr8so7507366ejc.12 for ; Thu, 09 Feb 2023 07:43:58 -0800 (PST) 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:subject:date :message-id:reply-to; bh=mNhlImrbcyyA3aOWoJ4bCR98Sw0/TarBltnda5ZH4o0=; b=2DX8upXew+ivvqfB8ftQtISe0fhl6krJ6Joq/djm12jzd3E8SWVf67k6IatqbWqI8Z isDb55TAbfRAGAnrC5BrolxrYbnU20VXs71s+0SvAYrLKUfNu1Fh6pLLV9WbOulwMMrL jni3sSUTnBRK9QsM4cjFtEOkgOUtSJNYWaUDE5CH/zRg3BrNw4GaRoeQpYRmXm7M5xjk BveKOmcqhp8UolmW2GmBk8BZV9C7N7F467tYvgufHBHkTwSjo38RCE2v3dFETOupuiPT jESjLD7C/U24bn8IERq3hAB9XnUFL9wfH1qQDoheFltHKdZ01IIhfKsly/TSb64SVQ/4 WaIg== 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 :subject:date:message-id:reply-to; bh=mNhlImrbcyyA3aOWoJ4bCR98Sw0/TarBltnda5ZH4o0=; b=TvoErXINYLgM5RnT5Z6zpSlzB1a5ucEIZsyNCBajOQ9TifKQ22hiP2kTm0LK6WZ83R hM9xCADg5gD4sEo4LYujJftAziTnqmOSqQcIKGePTS8cK5tmNkpv0VmuZPvoCCXdoc7k ySOE0knMVKe91kc2hv/0JCQOnzd9wS1No04g2NebWLhDw6zlDpFs5x0KtpsFQlfBJVtJ rOXwgfJ27w7gYekgpC5EP9UV4OYtvR/omZmE0aIED/JFADparP6F+2TV+9z2a5cFcZcn W0B1Uo84OrFax4KbHaF1O9SEA6snd0ZT/+1NkOCzg/SKqwn+Us6L0GNqgsE/8VYlvNa4 /SEQ== X-Gm-Message-State: AO0yUKXW4W115FT7o3dZrL/Ngi/DxzkyPranto5MHBDECDkZh4FnhRHl GWTc/Xpbd5QNXZn7RZg55h7GtLNuFTBnO22zd6A= X-Google-Smtp-Source: AK7set8NU2ecXTTZ5FUwOiOEC9UrMC3RBU4LwTTCf7uA/ZH2PbfrZ4iYbFd2pp3IWUa++uvjVfWrPw== X-Received: by 2002:a17:907:a45:b0:8af:1a8c:f13f with SMTP id be5-20020a1709070a4500b008af1a8cf13fmr7599950ejc.71.1675957405681; Thu, 09 Feb 2023 07:43:25 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id s20-20020a170906061400b0088ba2de323csm1005815ejb.181.2023.02.09.07.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:24 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 6/7] devlink: allow to call devl_param_driverinit_value_get() without holding instance lock Date: Thu, 9 Feb 2023 16:43:07 +0100 Message-Id: <20230209154308.2984602-7-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko If the driver maintains following basic sane behavior, the devl_param_driverinit_value_get() function could be called without holding instance lock: 1) Driver ensures a call to devl_param_driverinit_value_get() cannot race with registering/unregistering the parameter with the same parameter ID. 2) Driver ensures a call to devl_param_driverinit_value_get() cannot race with devl_param_driverinit_value_set() call with the same parameter ID. 3) Driver ensures a call to devl_param_driverinit_value_get() cannot race with reload operation. By the nature of params usage, these requirements should be trivially achievable. If the driver for some off reason is not able to comply, it has to take the devlink->lock while calling devl_param_driverinit_value_get(). Remove the lock assertion and add comment describing the locking requirements. This fixes a splat in mlx5 driver introduced by the commit referenced in the "Fixes" tag. Lore: https://lore.kernel.org/netdev/719de4f0-76ac-e8b9-38a9-167ae239efc7@amd.com/ Reported-by: Kim Phillips Fixes: 075935f0ae0f ("devlink: protect devlink param list by instance lock") Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- net/devlink/leftover.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 805c2b7ff468..775adcaa8824 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -9624,14 +9624,23 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister); * * This function should be used by the driver to get driverinit * configuration for initialization after reload command. + * + * Note that lockless call of this function relies on the + * driver to maintain following basic sane behavior: + * 1) Driver ensures a call to this function cannot race with + * registering/unregistering the parameter with the same parameter ID. + * 2) Driver ensures a call to this function cannot race with + * devl_param_driverinit_value_set() call with the same parameter ID. + * 3) Driver ensures a call to this function cannot race with + * reload operation. + * If the driver is not able to comply, it has to take the devlink->lock + * while calling this. */ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, union devlink_param_value *val) { struct devlink_param_item *param_item; - lockdep_assert_held(&devlink->lock); - if (WARN_ON(!devlink_reload_supported(devlink->ops))) return -EOPNOTSUPP; From patchwork Thu Feb 9 15:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13134814 X-Patchwork-Delegate: kuba@kernel.org 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 0241BC636D6 for ; Thu, 9 Feb 2023 15:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231293AbjBIPpA (ORCPT ); Thu, 9 Feb 2023 10:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231620AbjBIPoY (ORCPT ); Thu, 9 Feb 2023 10:44:24 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BF4A65673 for ; Thu, 9 Feb 2023 07:43:59 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id ud5so7609662ejc.4 for ; Thu, 09 Feb 2023 07:43:59 -0800 (PST) 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:subject:date :message-id:reply-to; bh=ahUNtoBUMUJEmN5YBzST2tGjBaSE++aFbMZBxs33E4A=; b=3agVf05Vg18i99L7Z0JFOAidJMiy1DNR2vmOwUIlP/5WFgbty5146RzZatOO8dWW/A qpj1knHGq8EvuDZuc8sLWzj4I8e4aerke+sCMc4jGHBh1L49D/YyqS7Q8IizHPoXZRoC vMnXcND8uOq/n6G6vihv9aambgkIezxmAnHzdT47JRypCup6XSX/asbfEvZxL/7IrymW dEO6TMxYdAtUj4YcmjvMBF2hnDtd3Ox6MHEmTkHB9b6Rdh6wgpFzRzbZnf9E3F5Ve1UW tLZTBPlNeqYbGAjCiwZVrMatOCaFqkoa5L/xyBquaQpz1LyPajdqOCkL8qNgPgqUxwD6 qHZA== 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 :subject:date:message-id:reply-to; bh=ahUNtoBUMUJEmN5YBzST2tGjBaSE++aFbMZBxs33E4A=; b=XG+NWbMvPZJpjbMioEP4M5YuC61E/HM2CtQ5OjVPefX6hIj9xtu0gkOt0I7ODQWfVw m8dwT0aqn0ps8w6rdoQ62vYp0vpBC1iT566Rdnw5mnY6fjhdLqNQTHt4dGIULOaHFHdF 77g7BbLGSD5sS3nQGWvpuuNtRWEN/ZUGUIYSaxcfmHicTWJZVl51PQnySj42gJsuxxRz CbWJW3QQm43knK3bdMcP59r2FB0xgl+rAVpe5OZRV+kJDtElTGuNMBICeZB3xlIwBS1n fELR9BfdzeT4mnDyNHRbSiBF1gnGbR5TCvTghKr+q2azEWT08el82lY+5EI1k9gjhuo+ Mr/A== X-Gm-Message-State: AO0yUKXRS8W7LgDRtLPenigJKFjYLcAb8/V2YNN4CfYWrnp0z+o1sLDV 8NwWoen+4QUHPlXrwePEehqRDEsWN8tDxDrMmB0= X-Google-Smtp-Source: AK7set8gkargCKvBVXyw3N+Hf7wxKT2R20PJhZHia7oPE2oZDYhpNbBARCO3wvdLaIehXBFULGKX9w== X-Received: by 2002:a17:907:9c04:b0:8ad:d366:54ca with SMTP id ld4-20020a1709079c0400b008add36654camr7051696ejc.23.1675957408553; Thu, 09 Feb 2023 07:43:28 -0800 (PST) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id la12-20020a170907780c00b008a7936de7b4sm1002286ejc.119.2023.02.09.07.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 07:43:27 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, tariqt@nvidia.com, saeedm@nvidia.com, jacob.e.keller@intel.com, gal@nvidia.com, kim.phillips@amd.com, moshe@nvidia.com Subject: [patch net-next 7/7] devlink: add forgotten devlink instance lock assertion to devl_param_driverinit_value_set() Date: Thu, 9 Feb 2023 16:43:08 +0100 Message-Id: <20230209154308.2984602-8-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209154308.2984602-1-jiri@resnulli.us> References: <20230209154308.2984602-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Driver calling devl_param_driverinit_value_set() has to hold devlink instance lock while doing that. Put an assertion there. Signed-off-by: Jiri Pirko Reviewed-by: Simon Horman --- net/devlink/leftover.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 775adcaa8824..ceacdb1cdf0b 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -9678,6 +9678,8 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, { struct devlink_param_item *param_item; + devl_assert_locked(devlink); + param_item = devlink_param_find_by_id(&devlink->params, param_id); if (WARN_ON(!param_item)) return;