From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 340D5C433ED for ; Wed, 12 May 2021 21:21:08 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 70D2F611BD for ; Wed, 12 May 2021 21:21:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70D2F611BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=E8HGGO80cde86QDWj+VGpfrsFY1xF5AOM875bxHmRZ0=; b=SypEupoAhp1iE0H0HPH//iM1ee U/zlSUoqSDHZXq+7L/Y8UoURD5L/Ha2HrKK8XiAvq0V5PuoVtmy9oJOGlB6InfpDd/YyYF2u4I9q9 JsFgRcJ3WYkbW1u7UroWOBoxXhSSfnKgDXmJIyRJXNypjMltaCf/Fc8rmc2mUjWy+XxcHXqipAe3/ NUrl73YthKWjjcOUNh/ZieG6K2/uJEoSHLUqvC1pEy663Y8AXX5BtP9f+7LjiiFJESYXd2wA6LKhn wxbg8b12vFXsx/RqMagUwAyN+lGOQI7l5snfMaYWB5jvwFdJH/bocerb2EQn0dUg3l1uFnQFWbsZA RCAoToMg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgwFC-0040Ud-SJ; Wed, 12 May 2021 21:18:15 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgwF5-0040Sf-0J for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 21:18:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mmU+ziRlyL6f5t/Combz3dolaekQmEheTrbdG+QX+BI=; b=x6EAwKJy+yduMncBIr9wSvrAZu Ypiz7eedeoD+N89/PoffujEHY47dSY/yIo3Ni6Jj5CKqBoupq1Ij+q+rssNUCagX90m7r0dDVMqhU NXWUD+n0xaFaHHDxaeQeNKLn75dGw7PTS6sOAEo2jhxXPF0Yfc7rxDht6ibDGSZxYKNooYhwv0F77 Z6O8qOpqj+ONyppIUR9hagg6z86TNDKR4cr6Ez0FPLWdA6ry/PR1bUrMj1I5fMGgxNS8w8fIeKyKE usi3osz1+WIXq9ChhrBYLISU1GK5ek8W1qtNVzpvSH/+qDRisK3qfbTzYBJGKbXlcyDsllVc4Oe/M lAA4UPRQ==; Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgwF2-00Apeo-6L for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 21:18:05 +0000 Received: by mail-wr1-x42a.google.com with SMTP id z17so5942727wrq.7 for ; Wed, 12 May 2021 14:18:03 -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=mmU+ziRlyL6f5t/Combz3dolaekQmEheTrbdG+QX+BI=; b=IHv/d7B2M5tyTKAkuWcLwy+a8w1Z1NlC+gfITmMqpQBtDEIhUWeyUdVRseU0Dga/or 18yoMJLffMaz+b/hqI9fQnEiTq/T2w/JAT7wr3b36e72hqw3aJpTOtP3fmY1x2i3NPsv tjG+p3y319E3tN6EPG1vX1K+ZfCU4zgtHzC49gkapTJ3zR8idGtnFaj63LRPPPcNiays g5WANFrnZDrHYy1/KyIabiIMZzRekQhUJQKcQGdocG+u23G5MTil15vPOVW+1REIW3PH 91xeI7P5PGsmO0LfsH8CrgZnRYtBr0YQ9iaAxGcGC+fI4+ZMvCXmlbvrih82fjx2FuIm 6ivQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mmU+ziRlyL6f5t/Combz3dolaekQmEheTrbdG+QX+BI=; b=giSYswDjUeFJJuUDmkS5MU7Zq2O36QdUkRqVZnpWlBsXNGY1LXQEvhKR7Bei6FPCiE m3uKNhvV/n9GlqhM+qKgC5EOoJ9q24LxCaxKDARII6lH0ajCJnix6Mzk3QyHpjIoZ3NC feAAhuF35FPg1UJ3J4xRIdm6rymCbeW9aMb0z9HTCA61PmCxRmXYM9Sd0few7sfEFVME nb86ppWC7h3px0MknTnM5KBG6xVGkvXtHdmBz5mKgC1jj7JwkgpJOnVSQhtiffqJ0h+O wz9eEquiJEeVvsZIUyeCcVLP5W3eqjdPu9cSeKXD732hdq7zdCBl3FSsX6IZ147I9Bol qX0Q== X-Gm-Message-State: AOAM533e6lfxvA+5mjyEZoMoerkcUzRQHwfBuj7DeeMks9g9MypolNXa /WbdSPWzZVn7lEz2tXi5ut6l6h/4I5q6UQ== X-Google-Smtp-Source: ABdhPJy6D9MK6w87UotmfAroa2gh2QyUSKwgBdrB6rIo9D+h1b7XdoNTHIbvNkTxo//jZ+oqV6RJAw== X-Received: by 2002:a5d:4a48:: with SMTP id v8mr48656390wrs.204.1620854282710; Wed, 12 May 2021 14:18:02 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:3d54:dc15:c65b:180c]) by smtp.gmail.com with ESMTPSA id e10sm908745wrw.20.2021.05.12.14.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 14:18:02 -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: [RFC PATCH 2/8] coresight: syscfg: Update load API for config loadable modules Date: Wed, 12 May 2021 22:17:46 +0100 Message-Id: <20210512211752.4103-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512211752.4103-1-mike.leach@linaro.org> References: <20210512211752.4103-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_141804_275146_B47116B0 X-CRM114-Status: GOOD ( 19.93 ) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- .../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 ab5ec43a9dad..26c1a244c2b1 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -368,6 +368,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; @@ -497,6 +517,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); @@ -547,7 +575,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); @@ -737,6 +769,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 @@ -777,6 +813,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, }; /** -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel