From patchwork Tue Oct 19 19:13:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12570977 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21A93C433F5 for ; Tue, 19 Oct 2021 19:15:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DF7D86137D for ; Tue, 19 Oct 2021 19:15:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DF7D86137D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:References:In-Reply-To: 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: List-Owner; bh=9lqXVy+0VflzLhQfwa/Al93YFs6NQuSxZeEMgDhlVo8=; b=rH0Em1OBJ9UaTC 0HEM5wdKEJE5xIK1hAZdNTdwpFHDlXHOXqzqR7sE72+oC4PX94ewGYBkRDyDRnQQf3RpFP9wNSPgw VfO4sF961ZfQCl6cYr7VWFXHoGQ3VINdmCPcdP6Uq7eiF/Eo38343dp/IIlx9ESHaPg7LWjJDI+QV s/ov4mWNgjLgF4Y32NsXXkFmr8x2pHRJvn3epe1/DMNyGQIUnYjJi2dUwxui2uB4eu5Pmcnjr6hDT 3hMaLvEH13Z8QX3nbo4dxj4whaSWB2a6v+qKVkB4xS84SSGo528cFjqo6mg8rQM/wKdMiDhGSvkU4 jrH5NgQOqrSf8i/HYSeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcuYs-002Tsq-Lv; Tue, 19 Oct 2021 19:14:10 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcuYe-002TpD-O0 for linux-arm-kernel@lists.infradead.org; Tue, 19 Oct 2021 19:13:58 +0000 Received: by mail-wm1-x331.google.com with SMTP id s198-20020a1ca9cf000000b0030d6986ea9fso5034210wme.1 for ; Tue, 19 Oct 2021 12:13:56 -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:in-reply-to:references; bh=gDdrDu1/2afLWfwg2gpG8vYDgeHMpPBJt2RBv+YkZiU=; b=SygfEyn65YsG4zT4B8r56MZfttVcN+drv+Sfspgxv/cQcc+w5f9ynNRqKsM3bnskz1 wJ9eilQF0FsyvsGn2KRKa4CaT49R8AaBp53ypX240JiXhv4m8CMq4wrINJ2FH7JfYIp6 ayyWtkMHacPkCyzlKrM1MFJaPhxDJkk3zTuBNAO+5xe3YuZwJUC+nu+U+Y2jysuSlGAQ YVnB9vqJH6bCLAouNUViI6R+UAZFdAEDwSMCLVmrJs/4CdQljUFy8lRB+7fLBnBkPcDx XnefjFHzUnabzVOHR7MaNEk6BhU58WuMZ9Y/hj/fM3RywG9kKSN6hFh61dO4W1P2u7uI n9gQ== 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:in-reply-to :references; bh=gDdrDu1/2afLWfwg2gpG8vYDgeHMpPBJt2RBv+YkZiU=; b=xxjtjjkBr3k+lPVeoTjQjc8CE38ocgA0EiSdqqDWwigfmesEt6emgCxyTxZUsewz5+ KHQ30lCSj2AyInVrCMG/YhCmpFSfPJgyNmbCPIVQ5/atdOm9xYoM4WKIbDiGWeQqveql QPLe4AuNnUWvCksAciBHYVoQHvdfoiilO6nCVQMizAg7hQ/0V7guwAODF2qLL+JnKcFF LdcPX2jerqadXYlKW7Bj0cFdqm224tGzXPZLANd2WufMPJVK7UDkUPC4OTEfp9vVG1+Z tQRA5zlGxx8aEUBWW1UMm4pH93c+b1U3femlRTN7hARpywydM5zh8pU28rzkdQsa/ReW TAWA== X-Gm-Message-State: AOAM532FikBTyDaE4/ndHfTYjXJVv4NVs6fwc59Hkngw7UAjDDB8oWLo P6ec/xSF1KS5y7DPokpl2LBx0g== X-Google-Smtp-Source: ABdhPJxJVjE6cvlpcjEMqp/YW52jYTcSA6Aw7pzZXOhqHdZ0rsECSe0W+bEPp5khjAqk1EjBSFW65A== X-Received: by 2002:adf:cf04:: with SMTP id o4mr46499150wrj.129.1634670834932; Tue, 19 Oct 2021 12:13:54 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:4cb1:37ba:8a95:ed1b]) by smtp.gmail.com with ESMTPSA id k22sm16012389wrd.59.2021.10.19.12.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 12:13:54 -0700 (PDT) From: Mike Leach To: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org, mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, Mike Leach Subject: [PATCH v2 2/5] coresight: syscfg: Update load API for config loadable modules Date: Tue, 19 Oct 2021 20:13:48 +0100 Message-Id: <20211019191351.10242-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211019191351.10242-1-mike.leach@linaro.org> References: <20211019191351.10242-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211019_121356_806630_A61E7808 X-CRM114-Status: GOOD ( 19.72 ) 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 CoreSight configurations and features can be added as kernel loadable modules. This patch updates the load owner API to ensure that the module cannot be unloaded either: 1) if the config it supplies is in use 2) if the module is not the last in the load order list. Signed-off-by: Mike Leach Reviewed-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-syscfg.c | 39 ++++++++++++++++++- .../hwtracing/coresight/coresight-syscfg.h | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 9bb0b0913a9a..4b91d8d9bc37 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -367,6 +367,26 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, return err; } +/* + * Conditionally up reference count on owner to prevent unload. + * + * module loaded configs need to be locked in to prevent premature unload. + */ +static int cscfg_owner_get(struct cscfg_load_owner_info *owner_info) +{ + if ((owner_info->type == CSCFG_OWNER_MODULE) && + (!try_module_get(owner_info->owner_handle))) + return -EINVAL; + return 0; +} + +/* conditionally lower ref count on an owner */ +static void cscfg_owner_put(struct cscfg_load_owner_info *owner_info) +{ + if (owner_info->type == CSCFG_OWNER_MODULE) + module_put(owner_info->owner_handle); +} + static void cscfg_remove_owned_csdev_configs(struct coresight_device *csdev, void *load_owner) { struct cscfg_config_csdev *config_csdev, *tmp; @@ -496,6 +516,14 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, /* add the load owner to the load order list */ list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list); + if (!list_is_singular(&cscfg_mgr->load_order_list)) { + /* lock previous item in load order list */ + err = cscfg_owner_get(list_prev_entry(owner_info, item)); + if (err) { + cscfg_unload_owned_cfgs_feats(owner_info); + list_del(&owner_info->item); + } + } exit_unlock: mutex_unlock(&cscfg_mutex); @@ -546,7 +574,11 @@ int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info) cscfg_unload_owned_cfgs_feats(owner_info); /* remove from load order list */ - list_del(&load_list_item->item); + if (!list_is_singular(&cscfg_mgr->load_order_list)) { + /* unlock previous item in load order list */ + cscfg_owner_put(list_prev_entry(owner_info, item)); + } + list_del(&owner_info->item); exit_unlock: mutex_unlock(&cscfg_mutex); @@ -738,6 +770,10 @@ int cscfg_activate_config(unsigned long cfg_hash) list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { if ((unsigned long)config_desc->event_ea->var == cfg_hash) { + /* must ensure that config cannot be unloaded in use */ + err = cscfg_owner_get(config_desc->load_owner); + if (err) + break; /* * increment the global active count - control changes to * active configurations @@ -778,6 +814,7 @@ void cscfg_deactivate_config(unsigned long cfg_hash) if ((unsigned long)config_desc->event_ea->var == cfg_hash) { atomic_dec(&config_desc->active_cnt); atomic_dec(&cscfg_mgr->sys_active_cnt); + cscfg_owner_put(config_desc->load_owner); dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); break; } diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h index e2b2bdab31aa..1da37874f70f 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -61,6 +61,7 @@ struct cscfg_registered_csdev { /* owner types for loading and unloading of config and feature sets */ enum cscfg_load_owner_type { CSCFG_OWNER_PRELOAD, + CSCFG_OWNER_MODULE, }; /**