Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1555228ybt; Thu, 2 Jul 2020 08:12:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQnn5IKd4jiwO/sfaaicfizabNL4Z1WYq9phXqxCVsdGyIgPwqrT4RgkhgY7siYJxz8A34 X-Received: by 2002:a17:906:5008:: with SMTP id s8mr17164967ejj.147.1593702768640; Thu, 02 Jul 2020 08:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593702768; cv=none; d=google.com; s=arc-20160816; b=0kPrWFVLMZcf4pZGISmFXpCrryWEJV7q6/v751UiUoQ+3dCBSdDNHC1WhP+a1UIiXI 5RCw7iFT4mhIUke1idQwrtOshu5nakvSEGRkjWp06yhcL8yAKsacFLlvrFkCrTn0o9Ah CFFYOof1zTotpATjEZQDrS3KiXBKspwvgeWsVoWySyVJX5uMgSksqmxgIAIA6Qz/v1zy AutLJc45ydLbs5+pqer++OfIxkC7PFSaGPfl7/bwyhHHU4oRmTPiN+5IFWWQCvZdf82q UO+JGKRAaQf/KHSTaekekCwh9MyJE3yOs4FSFbPGN0Ki9Jh9yP79ptXrGZeDkkAWdD5V MG+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=rG2Y80XooZqn8CuMMV0U1z4g80MS+asKA4h8rxg9VO0=; b=unConZEKRPmWZo3CekW87LwJ0gV6/9LE/07d0Fmaz39pgn70hdwAvpzMscZhijiUq2 VW6aWQfwVQganszlxP4OZyoVfpqH//Cw2ohYs82QhXU55+q7uVdS72y2vgAlVvJsUJEe rKtiei8T/bjwv+vcpBhh1RUwAcEpVTI9CYZQAIH/g+3kv1lXaFH4YGA4DZZNF0ApZIaP qx3vfmlfLqWLQkiFL8B0Xo9zzkSVwMUPDmkS3L3z4OVzRwE2jjE3pdF+fv+0+H5YhehK Srd4Tv5TavV45rqwapYe6tGSebCIdNiL96gBQplVkDmZEZo8r/RK/fTUpES+LhmO+iuP cJdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si6476279ejm.227.2020.07.02.08.12.25; Thu, 02 Jul 2020 08:12:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730014AbgGBPJM (ORCPT + 99 others); Thu, 2 Jul 2020 11:09:12 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:39725 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729360AbgGBPJL (ORCPT ); Thu, 2 Jul 2020 11:09:11 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 2 Jul 2020 18:09:08 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (dev-l-vrt-136.mtl.labs.mlnx [10.234.136.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 062F98hm020260; Thu, 2 Jul 2020 18:09:08 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7) with ESMTP id 062F98xb015407; Thu, 2 Jul 2020 18:09:08 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 062F98rp015406; Thu, 2 Jul 2020 18:09:08 +0300 From: Moshe Shemesh To: "David S. Miller" Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vladyslav Tarasiuk Subject: [PATCH net-next 2/7] devlink: Rework devlink health reporter destructor Date: Thu, 2 Jul 2020 18:08:08 +0300 Message-Id: <1593702493-15323-3-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1593702493-15323-1-git-send-email-moshe@mellanox.com> References: <1593702493-15323-1-git-send-email-moshe@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladyslav Tarasiuk Devlink keeps its own reference to every reporter in a list and inits refcount to 1 upon reporter's creation. Existing destructor waits to free the memory indefinitely using msleep() until all references except devlink's own are put. Rework this mechanism by moving memory free routine to a separate function, which is called when the last reporter reference is put. Besides, it allows to call __devlink_health_reporter_destroy() while locked on a reporters list mutex in symmetry to __devlink_health_reporter_create(), which is required in follow-up patch. Signed-off-by: Vladyslav Tarasiuk Reviewed-by: Moshe Shemesh Reviewed-by: Jiri Pirko --- net/core/devlink.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index dfd7fe2..dcf8006 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5353,6 +5353,29 @@ struct devlink_health_reporter * } EXPORT_SYMBOL_GPL(devlink_health_reporter_create); +static void +devlink_health_reporter_free(struct devlink_health_reporter *reporter) +{ + mutex_destroy(&reporter->dump_lock); + if (reporter->dump_fmsg) + devlink_fmsg_free(reporter->dump_fmsg); + kfree(reporter); +} + +static void +devlink_health_reporter_put(struct devlink_health_reporter *reporter) +{ + if (refcount_dec_and_test(&reporter->refcount)) + devlink_health_reporter_free(reporter); +} + +static void +__devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) +{ + list_del(&reporter->list); + devlink_health_reporter_put(reporter); +} + /** * devlink_health_reporter_destroy - destroy devlink health reporter * @@ -5362,14 +5385,8 @@ struct devlink_health_reporter * devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) { mutex_lock(&reporter->devlink->reporters_lock); - list_del(&reporter->list); + __devlink_health_reporter_destroy(reporter); mutex_unlock(&reporter->devlink->reporters_lock); - while (refcount_read(&reporter->refcount) > 1) - msleep(100); - mutex_destroy(&reporter->dump_lock); - if (reporter->dump_fmsg) - devlink_fmsg_free(reporter->dump_fmsg); - kfree(reporter); } EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy); @@ -5639,12 +5656,6 @@ int devlink_health_report(struct devlink_health_reporter *reporter, return NULL; } -static void -devlink_health_reporter_put(struct devlink_health_reporter *reporter) -{ - refcount_dec(&reporter->refcount); -} - void devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, enum devlink_health_reporter_state state) -- 1.8.3.1