From owner-svn-src-stable-12@freebsd.org Thu Dec 17 17:21:12 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DED714BDA8F; Thu, 17 Dec 2020 17:21:12 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cxf0m61zbz4Rxr; Thu, 17 Dec 2020 17:21:12 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C24261C1D8; Thu, 17 Dec 2020 17:21:12 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BHHLCqs081626; Thu, 17 Dec 2020 17:21:12 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BHHLCp4081625; Thu, 17 Dec 2020 17:21:12 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202012171721.0BHHLCp4081625@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 17 Dec 2020 17:21:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r368726 - stable/12/sys/cddl/dev/sdt X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/12/sys/cddl/dev/sdt X-SVN-Commit-Revision: 368726 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 17:21:12 -0000 Author: markj Date: Thu Dec 17 17:21:12 2020 New Revision: 368726 URL: https://svnweb.freebsd.org/changeset/base/368726 Log: MFC r368306: sdt: Create providers and probes in separate passes when loading sdt.ko Modified: stable/12/sys/cddl/dev/sdt/sdt.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cddl/dev/sdt/sdt.c ============================================================================== --- stable/12/sys/cddl/dev/sdt/sdt.c Thu Dec 17 17:11:14 2020 (r368725) +++ stable/12/sys/cddl/dev/sdt/sdt.c Thu Dec 17 17:21:12 2020 (r368726) @@ -271,26 +271,24 @@ sdt_destroy(void *arg, dtrace_id_t id, void *parg) { } -/* - * Called from the kernel linker when a module is loaded, before - * dtrace_module_loaded() is called. This is done so that it's possible to - * register new providers when modules are loaded. The DTrace framework - * explicitly disallows calling into the framework from the provide_module - * provider method, so we cannot do this there. - */ static void -sdt_kld_load(void *arg __unused, struct linker_file *lf) +sdt_kld_load_providers(struct linker_file *lf) { struct sdt_provider **prov, **begin, **end; - struct sdt_probe **probe, **p_begin, **p_end; - struct sdt_argtype **argtype, **a_begin, **a_end; if (linker_file_lookup_set(lf, "sdt_providers_set", &begin, &end, NULL) == 0) { for (prov = begin; prov < end; prov++) sdt_create_provider(*prov); } +} +static void +sdt_kld_load_probes(struct linker_file *lf) +{ + struct sdt_probe **probe, **p_begin, **p_end; + struct sdt_argtype **argtype, **a_begin, **a_end; + if (linker_file_lookup_set(lf, "sdt_probes_set", &p_begin, &p_end, NULL) == 0) { for (probe = p_begin; probe < p_end; probe++) { @@ -310,7 +308,21 @@ sdt_kld_load(void *arg __unused, struct linker_file *l } } +/* + * Called from the kernel linker when a module is loaded, before + * dtrace_module_loaded() is called. This is done so that it's possible to + * register new providers when modules are loaded. The DTrace framework + * explicitly disallows calling into the framework from the provide_module + * provider method, so we cannot do this there. + */ static void +sdt_kld_load(void *arg __unused, struct linker_file *lf) +{ + sdt_kld_load_providers(lf); + sdt_kld_load_probes(lf); +} + +static void sdt_kld_unload_try(void *arg __unused, struct linker_file *lf, int *error) { struct sdt_provider *prov, **curr, **begin, **end, *tmp; @@ -348,16 +360,21 @@ sdt_kld_unload_try(void *arg __unused, struct linker_f } static int -sdt_linker_file_cb(linker_file_t lf, void *arg __unused) +sdt_load_providers_cb(linker_file_t lf, void *arg __unused) { + sdt_kld_load_providers(lf); + return (0); +} - sdt_kld_load(NULL, lf); - +static int +sdt_load_probes_cb(linker_file_t lf, void *arg __unused) +{ + sdt_kld_load_probes(lf); return (0); } static void -sdt_load() +sdt_load(void) { TAILQ_INIT(&sdt_prov_list); @@ -369,12 +386,17 @@ sdt_load() sdt_kld_unload_try_tag = EVENTHANDLER_REGISTER(kld_unload_try, sdt_kld_unload_try, NULL, EVENTHANDLER_PRI_ANY); - /* Pick up probes from the kernel and already-loaded linker files. */ - linker_file_foreach(sdt_linker_file_cb, NULL); + /* + * Pick up probes from the kernel and already-loaded linker files. + * Define providers in a separate pass since a linker file may be using + * providers defined in a file that appears later in the list. + */ + linker_file_foreach(sdt_load_providers_cb, NULL); + linker_file_foreach(sdt_load_probes_cb, NULL); } static int -sdt_unload() +sdt_unload(void) { struct sdt_provider *prov, *tmp; int ret;