From patchwork Mon Jun 6 15:26:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12870586 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB96DC43334 for ; Mon, 6 Jun 2022 15:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5WaYaoftvWoCEwOz4Cp1L9gNIUWJF8sTQMM/ahvfQHA=; b=RUzPd5AjijU7hg CYxwrJsH8BYl2OdpRs+EDEEICWe4hbwzOCKJ0+R2Wni0jZntH4DMP9r+7KZvsBkjyIH8SO5N73w6Y 34eVBjqxL2RxFr2C0+jPJ9l6FFyHpfCg06OIDVIZmpeBK3SXUK4VGkUb52V3OxpDLTxXpdPot23+u Xx7dTy4EsTFC2LzyCXV327+4GvFScIpWI8xKWBBBd1YRNEgW6p730ZHUtMXW3UAs4ZYnw3HSk15sb tEHdD+hqNiXIvUD/9Fgt7Tl7Q7o96a/FGD9LuUYw/QxrGyEMotv5TggCTxUEu4Yztz/TMW9Ag9JWf QvR/wUBFHrywQSTuXrNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyEh8-001pf5-CQ; Mon, 06 Jun 2022 15:31:06 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyEcs-001nRV-MX for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2022 15:26:44 +0000 Received: by mail-wr1-x430.google.com with SMTP id x17so20340799wrg.6 for ; Mon, 06 Jun 2022 08:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=jA6Ikp6WhA9jGv0suJZhd4WBJyBwmp7zRAfsjysrezk=; b=UkANKdX5BnbYQ4C1hErXsWbz1HB4GE7ba3gUYFv4DW7MsPHBg8roKq6PHEkNWmft58 iQAjboU2kR6DtsGk94Wm1jNDLmUTi1uk7pj7MB3/97ojenoZglLqhEhG/wDbangIr4aW dHzCPgmzSUMBRvAaW+fGpicre5xfa6VNtpxZWBZjwq+tdBLKO37Kb7vG+v3zbarZkC5F rpW7KhLhaaStF3yArtqd5OLUka8Sxe9FWaLNdLZj6HRTHDLiyvwunO2bFFliVR4WUiS/ MGUO9jQeKRZEgOaWWgIcXxV/dXCjTgSUbiinhT6Q1Xwnksr9iRSITFKok01paUDwhN2p vVSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jA6Ikp6WhA9jGv0suJZhd4WBJyBwmp7zRAfsjysrezk=; b=G5RDMEAmB2o5fdBWuCMJT6JYCk7q8kua/dbZjWt6zeCZzHu/mkxfXepfTbHcqhxnvU dfo+vJewvYhyvtn3DNNAblLnNlhXNDamSeg2LSn0cwzj6/o8PwWcixaz883916nh/pso Tler3RQhj/4UWHz5ePuRjXQKstDuaG/6cSRdKIh8QBu6UhNPUgFD5RlK0s6VuiP+9jc1 uXNzSrkuXitD8k+M6RtWGn76NdA4O0n9OKWEop+DvT94NsgzntE+6jqnWPwQwNXesAo5 IGf2opEAg5ci7IQ4D7tlF9l+jM/carEn1M1FEw83PFaWA1w0dFTkZ+NIjkPPs1Wf14UH 6LBg== X-Gm-Message-State: AOAM531AQzQJuhKRdgPe9QQAK8m4v14eeU050GruXBb4viMTyN0nrxWi JuPKwLnLqSmMDpGUQCmwEK2932x/4N5Zuw== X-Google-Smtp-Source: ABdhPJzgbvRuLO4sTK42ji3GLZqUTEU9hDqL4KN2tyYkZvnmoeT4IsXr+LmF1DaI/7qvQ/QsSGIuTQ== X-Received: by 2002:a05:6000:168c:b0:218:4523:c975 with SMTP id y12-20020a056000168c00b002184523c975mr3089036wrd.23.1654529199596; Mon, 06 Jun 2022 08:26:39 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:9043:4ba4:7063:66e0]) by smtp.gmail.com with ESMTPSA id o34-20020a05600c512200b003944821105esm19773850wms.2.2022.06.06.08.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 08:26:38 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, suzuki.poulose@arm.com Cc: mathieu.poirier@linaro.org, leo.yan@linaro.org, Mike Leach Subject: [PATCH v2] coresight: configfs: Fix unload of configurations on module exit Date: Mon, 6 Jun 2022 16:26:36 +0100 Message-Id: <20220606152636.3996-1-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220606_082642_839918_C4B230F2 X-CRM114-Status: GOOD ( 23.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Any loaded configurations must be correctly unloaded on coresight module exit, or issues can arise with nested locking in the configfs directory code if built with CONFIG_LOCKDEP. Prior to this patch, the preloaded configuration configfs directory entries were being unloaded by the recursive code in configfs_unregister_subsystem(). However, when built with CONFIG_LOCKDEP, this caused a nested lock warning, which was not mitigated by the LOCKDEP dependent code in fs/configfs/dir.c designed to prevent this, due to the different directory levels for the root of the directory being removed. As the preloaded (and all other) configurations are registered after configfs_register_subsystem(), we now explicitly unload them before the call to configfs_unregister_subsystem(). The new routine cscfg_unload_cfgs_on_exit() iterates through the load owner list to unload any remaining configurations that were not unloaded by the user before the module exits. This covers both the CSCFG_OWNER_PRELOAD and CSCFG_OWNER_MODULE owner types, and will be extended to cover future load owner types for CoreSight configurations. Applies to coresight/next Fixes: eb2ec49606c2 ("coresight: syscfg: Update load API for config loadable modules") Reported-by: Suzuki Poulose Signed-off-by: Mike Leach --- Changes since v1: Altered ordering of init of cscfg_mgr to ensure lists valid for potential exit path on error. --- .../hwtracing/coresight/coresight-syscfg.c | 72 ++++++++++++++++--- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 11850fd8c3b5..050a32f7e439 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -1042,6 +1042,13 @@ static int cscfg_create_device(void) if (!cscfg_mgr) goto create_dev_exit_unlock; + /* initialise the cscfg_mgr structure */ + INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list); + INIT_LIST_HEAD(&cscfg_mgr->feat_desc_list); + INIT_LIST_HEAD(&cscfg_mgr->config_desc_list); + INIT_LIST_HEAD(&cscfg_mgr->load_order_list); + atomic_set(&cscfg_mgr->sys_active_cnt, 0); + /* setup the device */ dev = cscfg_device(); dev->release = cscfg_dev_release; @@ -1056,14 +1063,61 @@ static int cscfg_create_device(void) return err; } -static void cscfg_clear_device(void) +/* + * Loading and unloading is generally on user discretion. + * If exiting due to coresight module unload, we need to unload any configurations that remain, + * before we unregister the configfs intrastructure. + * + * Do this by walking the load_owner list and taking appropriate action, depending on the load + * owner type. + * + * called with the cscfg_mutex held + */ + +#define LOADABLE_MOD_ERR "cscfg: ERROR - a loadable module failed to unload configs on exit\n" + +static void cscfg_unload_cfgs_on_exit(void) { - struct cscfg_config_desc *cfg_desc; + struct cscfg_load_owner_info *owner_info = NULL; - mutex_lock(&cscfg_mutex); - list_for_each_entry(cfg_desc, &cscfg_mgr->config_desc_list, item) { - etm_perf_del_symlink_cscfg(cfg_desc); + while (!list_empty(&cscfg_mgr->load_order_list)) { + + /* remove in reverse order of loading */ + owner_info = list_last_entry(&cscfg_mgr->load_order_list, + struct cscfg_load_owner_info, item); + + /* action according to type */ + switch (owner_info->type) { + case CSCFG_OWNER_PRELOAD: + /* + * preloaded descriptors are statically allocated in + * this module - just need to unload dynamic items from + * csdev lists, and remove from configfs directories. + */ + pr_info("cscfg: unloading preloaded configurations\n"); + cscfg_unload_owned_cfgs_feats(owner_info); + break; + + case CSCFG_OWNER_MODULE: + /* + * this is an error - the loadable module must have been unloaded prior + * to the coresight module unload. Therefore that module has not + * correctly unloaded configs in its own exit code. + * Nothing to do other than emit an error string. + */ + pr_err(LOADABLE_MOD_ERR); + break; + } + + /* remove from load order list */ + list_del(&owner_info->item); } +} + +static void cscfg_clear_device(void) +{ + mutex_lock(&cscfg_mutex); + cscfg_unload_cfgs_on_exit(); cscfg_configfs_release(cscfg_mgr); device_unregister(cscfg_device()); mutex_unlock(&cscfg_mutex); @@ -1074,20 +1128,16 @@ int __init cscfg_init(void) { int err = 0; + /* create the device and init cscfg_mgr */ err = cscfg_create_device(); if (err) return err; + /* initialise configfs subsystem */ err = cscfg_configfs_init(cscfg_mgr); if (err) goto exit_err; - INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list); - INIT_LIST_HEAD(&cscfg_mgr->feat_desc_list); - INIT_LIST_HEAD(&cscfg_mgr->config_desc_list); - INIT_LIST_HEAD(&cscfg_mgr->load_order_list); - atomic_set(&cscfg_mgr->sys_active_cnt, 0); - /* preload built-in configurations */ err = cscfg_preload(THIS_MODULE); if (err)