Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1990573ybt; Thu, 2 Jul 2020 20:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqkNYpAm76wp7zOUxcqz76PO/D3blVY/6xIJOlJTtZsC8ej1wWZxCVRiFuXyXdj+j9KfxA X-Received: by 2002:a17:906:414c:: with SMTP id l12mr9763599ejk.417.1593747058160; Thu, 02 Jul 2020 20:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593747058; cv=none; d=google.com; s=arc-20160816; b=EQdJcyt5mW8whm3xKrVP+SQbzfdjaW3OmHxqwJUI4Ofz2vve2GeERAvxzF5iM42bQt e9FQTJOrOEESvlc8OM27B3/0yE3CZ7Ec3y+R9RfqvAtuFvYnlDxqnsYn3ihUF5sZeZAN /eGJQB13okOSjoURLRavlqjfh83xBTtG0rt2p/6hi1c1b4GhImeTl65/GDHZi3Z8quD7 XfcjzXm2I+oVQO4mm7rsIajdyJCmgh1Gd88qBbpqCH0cOuBqj8AxNXSB0CJxTUIAPmvP yrgRn4oUEMxIkRlTTi5Pu/eIVyoHKU97zFB1+LoRTa0/msO51VJha7oCshW4xpHtptTp N0SQ== 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=TAFCn+uNafvduu6Y+udtjDY0WD4paWlgHdYGXDrueLaLd2SrE4OIfPwwG4KtCIfSxY kX2T6bH+pMEoKCVxTaTgUH6ZBzcNxmlgpP2c4tdG2APfPwINlfhJgajrQldd73kSwfY0 uLAnvx4591uvZtjSYm60mBn18oxPcZuNq9x/MV12ljDbVjdPy3rTX6Ex9YZpCxpXqfwe Eei5nTkpG3XQBI4l72PQIWIFtQ52dwVMrXD98brkxs1zhXqkrIB17wnXRTDygy2NN3Dp GNxjceMXmNdJrIZzKbfFbeahsuBSkTQe3u0WQTJ8w5WyOPCn8HzjipPcdo3rSoRRP7YD c2UQ== 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 p19si7272690ejw.369.2020.07.02.20.30.34; Thu, 02 Jul 2020 20:30:58 -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 S1726352AbgGCD2y (ORCPT + 99 others); Thu, 2 Jul 2020 23:28:54 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:33603 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726119AbgGCD2V (ORCPT ); Thu, 2 Jul 2020 23:28:21 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 3 Jul 2020 06:28:15 +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 0633SFp3006786; Fri, 3 Jul 2020 06:28:15 +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 0633SFxi006659; Fri, 3 Jul 2020 06:28:15 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 0633SE3a006658; Fri, 3 Jul 2020 06:28:14 +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 v2 2/7] devlink: Rework devlink health reporter destructor Date: Fri, 3 Jul 2020 06:27:33 +0300 Message-Id: <1593746858-6548-3-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1593746858-6548-1-git-send-email-moshe@mellanox.com> References: <1593746858-6548-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