Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp499745ybt; Fri, 10 Jul 2020 05:30:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJR5tUMlQctmfv+DKKayQMfqxLCOmyu+jZA3qHXEBAB4JnA+/tTVziPW3IGGflBKROkY5J X-Received: by 2002:aa7:d50d:: with SMTP id y13mr76819305edq.230.1594384212443; Fri, 10 Jul 2020 05:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594384212; cv=none; d=google.com; s=arc-20160816; b=cUSBJA3GSiH9sMCafkAU5YMA5gh2WOJMZTU0gMzS9JCan1mdoYFWpm53fuAi6rRt1s r2yQH5xJWC8DDBo2fCoaShjYYug3hdz+QYoetsyzG3AJkuKyDo2z7AGBbcNkJ6JUzepG WRG8XJhu1gKeVZSQzLOa3ZoNug5Wpko1UMhQhz7b744BTpXm0txBeATL6J4qGrCZA2jv 7V4LFYZcAB8oC297hBxwzeyUPPkQERstkl5rjwqJpcZeo8BUbNP9lXB++pbcCkisTEcy btt3iS9SV/m2jpyPE1n8vMTbbrb3pssaXF7VzbWIEXmehtbBKJezu6qjmcvVtbTOiZLv YpqQ== 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=6A1c31f28xXjLzyakrL3zE3kgWPdeTGNnmSupNow4g8=; b=O1FHJV5ctlwqyS6VWl18sevb8cadVSLzWxS/ra3HtDQPU3SC30bb2Utn8g4YS43JDD EWoNLIf2VElVmeqcHDzhe2uPMWyWtFskckOqpCWno3RIGGu0RYsQSM/Ms1UBQosq4Uiz /hitoXNNxZEje4oPCilQAHVRjD/3Acsb1wfnrlm6QWP3YPG+X+lVLdCRIeE04/bG5QXe wuV7I5lhRA0zAHwJJmmTrXJmhvnthWkWmqvIbYPHCnHU6BZrJCUhFsHI3iw13W3O4Pw/ LZD+wHqSYP0ym7QtZGMimAktOQn+GDV6pgUSwsiektelws9yPtmAdUhm59O0FQNtvuqp BPBQ== 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 g7si3673734ejr.748.2020.07.10.05.29.48; Fri, 10 Jul 2020 05:30:12 -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 S1728056AbgGJM01 (ORCPT + 99 others); Fri, 10 Jul 2020 08:26:27 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:51773 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727863AbgGJMZ4 (ORCPT ); Fri, 10 Jul 2020 08:25:56 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 10 Jul 2020 15:25:48 +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 06ACPm6q012390; Fri, 10 Jul 2020 15:25:48 +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 06ACPmAL003372; Fri, 10 Jul 2020 15:25:48 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 06ACPmTx003370; Fri, 10 Jul 2020 15:25:48 +0300 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vladyslav Tarasiuk Subject: [PATCH net-next v3 2/7] devlink: Rework devlink health reporter destructor Date: Fri, 10 Jul 2020 15:25:08 +0300 Message-Id: <1594383913-3295-3-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1594383913-3295-1-git-send-email-moshe@mellanox.com> References: <1594383913-3295-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 a203d35..b85f211 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5379,6 +5379,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 * @@ -5388,14 +5411,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); @@ -5665,12 +5682,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