From patchwork Mon May 30 17:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12864808 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 507ADC433EF for ; Mon, 30 May 2022 17:18:51 +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=LHhOvrpnor3HBFeWmUhZjk49gPnz5YjS4/6PEN8FzvA=; b=pBkypq1Wivm2D6 xWk77OyasbJdqcLSoZX/7CDczX32UHJ8uiDa4dhUMXTYmPlqB77L+A1oH73R1himSPpDLnSsoLzWz dduC5VZ1UEuhuqn+uMm6jQSq2bK7Mwo3vaRr+2Cjc8+izH7lBJi+awVaYDtAyFsYP2E3J29g9MFZm ONXeL//TMSdAOeoj7Hlbew22W9qDfVo9ER9EITb32haCNEbndCXqYPSfku417BABruHOwaCnlkATS qNbh1jceJ2foveCLrE0Aztjcre18froknFGRc9ngQRltGUV1IS7v+dZVbpTAHLRHOV9cQl3CH2vqV F8Knqxw4asYMkFL3PsXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvj1I-007hbB-TV; Mon, 30 May 2022 17:17:33 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvj1F-007hZZ-7Q for linux-arm-kernel@lists.infradead.org; Mon, 30 May 2022 17:17:30 +0000 Received: by mail-wr1-x42d.google.com with SMTP id s24so8209643wrb.10 for ; Mon, 30 May 2022 10:17:26 -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=lQwLPt1D8E1EA8Vbn4uqPhAY0xWUPWvKaHUJiL1JkPQ=; b=fxYdvKs8MwM3iRrkAV81n69iiv6+GO76xYjvVdo89RK3OJ9h5SqOJVMCIctjg9t6qD rr93AhFCHFbR6hJ4RB9iH2gOTpDI2THnkcB7rMT4Jer5yt5WDaKTseRHLz7oDb80YD4X pki0WdBx3fzoj1F3LTS2p5qRCS5tC6M+6kr4X58rhbuGG02shkAUBuerkLljCBk/p83h bw6vWJCaEAo0W2z0rc5/itFtfBBWzAcNk+bCCZlQRjrqx+Y7VBmcteO15qH59r9oEo4f 7onzKSHdE+ux2JLhjuaHCOL+LT6Rt0S9bpC8qjU10M5J/An+fjKzdZYvCuQRbEg3H6j8 d6lQ== 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=lQwLPt1D8E1EA8Vbn4uqPhAY0xWUPWvKaHUJiL1JkPQ=; b=23eE0/ryR3s/U6aYKXvBCMOAgnlpxMgeqxAcxlxTRF3m1gc85r5in5u+a8qCBucoiN aZnhwuKvjhE6n69Ri43hYZVeGLXnmy9EbXknDrS5GVXW70BZGf0WuuZU3PlqcbZodVPK NbQM0GiXKmXWPr39l+PB+z3Ifw/oN3GcJjQVtGl5UahzQtV/OeiXiSbq4UHDZZmGAW+b TyzvphPF/WWvsJA3ndTw71Jb/FuQHjQRLyW/pHPoj/vjD+v7bssisuQVPUMc9Vr50MJ/ kE6ZXOnasCMeg+28CTPUJlyQqvI3lkRpsbUexCCG1hl1ySVT/LYuRNA8l+I4dupD7hFR ngFw== X-Gm-Message-State: AOAM533kbnK0qz8n4Wz9IgzI6CgUtk+iZIqziCA5VWbr/Jbcj64TfiHh gzO/fbMbdPyUq/vuT/rTCz+Nt9BQkj7SKQ== X-Google-Smtp-Source: ABdhPJxws28irKeS+UTqHJtZnZ6W0+A/mYgbpBEwWD+o+jvUXX938AgBHsikXOL/nelzbphxbd2zRQ== X-Received: by 2002:a5d:4906:0:b0:20f:fc2a:987a with SMTP id x6-20020a5d4906000000b0020ffc2a987amr22496304wrq.228.1653931042410; Mon, 30 May 2022 10:17:22 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:ac68:588c:6403:cf3c]) by smtp.gmail.com with ESMTPSA id z8-20020a05600c0a0800b0039c15ff3200sm2307399wmp.41.2022.05.30.10.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 10:17:20 -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, Mike Leach Subject: [PATCH] coresight: configfs: Fix unload of configurations on module exit Date: Mon, 30 May 2022 18:17:17 +0100 Message-Id: <20220530171717.12253-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-20220530_101729_308833_A4F01596 X-CRM114-Status: GOOD ( 20.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 --- .../hwtracing/coresight/coresight-syscfg.c | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 11850fd8c3b5..75df0f865355 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -1056,14 +1056,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);