From patchwork Fri Mar 10 14:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 67467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp948554wrd; Fri, 10 Mar 2023 07:54:11 -0800 (PST) X-Google-Smtp-Source: AK7set/Cl4S0vw0KsTpNsfwwzEP36xrzuExGFuEw+nXvY0ISxTL2/PWYdPL9yYki2yk0XKgcI7fA X-Received: by 2002:a62:3045:0:b0:61d:eb94:bcbd with SMTP id w66-20020a623045000000b0061deb94bcbdmr8293072pfw.14.1678463651192; Fri, 10 Mar 2023 07:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678463651; cv=none; d=google.com; s=arc-20160816; b=pqsmnsRdnFeFuFGhXhaCHcHv5p6Q6/9S2lDxY7Fj1X4kcE8xc5Auw1VNFGnvIO/4z8 CnM0Z6m31fuRUzKdmhLhm8eqy+MmMzimeSnxfsKKY1lF4joFUJZYVJ0Uy6SFK18HrF7u oMMl9/D5oQflxMXtPVRd7SCmIK2vh2/WHt6tQHeyroJIeLeqqRpsE64d1AJSPaFP4v0u zkO0cR7GBs5QVvFIKEKaQHJiAsGxbL+DPLCH8l+1uBzt0AR+HgxB2GPH317EfrShBtV9 rCRWkdOLSDKqu/pNigOpO/0XOmcGpNw6ZqO+oi9wyx1EAz7rmTtv82hmNP3hjCdZv4jH KN2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NEDWllyBipxPa8k8R9SdufDWTOGJaXzanPSnd5DT0jk=; b=Qm9J0NwRrfBrevLhFPYQGdQXaUaiPnGLDxqu62zTSj7+kvu9GIhaI8JTvxFYKOZ0ly APb1uhnkDXJz7Jk/V1sqk34dOP6Vdd7Pc63MbUF2LxZqRXvE76d2qzNOObq4cKH6KqYR RS4XM29jNXCraBSiraKDTR65yyaNq7+zsyWDZcGs0X8I5sxtBjDA55u/OGas/ux3SFsy 200Dj8NsZKjBhDYaKn1QvduJuyqlV7pc6+P1Sai8BbM87X3s4ahqMLP98Gkq1oUFXARo Vi8nXUNrda8kc4Qp4acUUwS9WVFjWoI3HviExR5Z6GfbPOuOUfyoVzpFWHFwyj3ivKMj sDYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aQme9I63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v2-20020aa799c2000000b005a90ee7188fsi24076pfi.49.2023.03.10.07.53.58; Fri, 10 Mar 2023 07:54:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aQme9I63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbjCJOGC (ORCPT + 99 others); Fri, 10 Mar 2023 09:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbjCJOFz (ORCPT ); Fri, 10 Mar 2023 09:05:55 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 516C3112DDE for ; Fri, 10 Mar 2023 06:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678457127; x=1709993127; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=zhuEA1E7XMHriDQ8E6NYA18+POSomu37M3uwwjoBtFc=; b=aQme9I63jk08tsP5Swi663qUV1+WEXtEsJzMrLjxCCy8yT85DKE/qXdR b3Wo5reGBxSTSuIeoB3hpAToRplB2WNL2wL1hfEyYivmxyatVlRkjOecs 4bBJOfkONfWL5ad509mc0m0Hm3xEMZ/DRMXfN0tBl+FxOLrgAA2YmXnXT I68Zh4MD7CKlOH9TCEjDBMPZi+CP4IbjH4JTXtZI8AMD4s5ibC2jgVaz8 NI5AFybbOXgFG/UZw7/MDww9LLH6l7sJOAl+xp68DH/09oXVgGmB0hfBs y598YdSh/w2PV1+MWeeYl/XYSxlyQBqhboQ+G64AMg/I44V/RiMxEKa5x w==; X-IronPort-AV: E=McAfee;i="6500,9779,10645"; a="399330874" X-IronPort-AV: E=Sophos;i="5.98,249,1673942400"; d="scan'208";a="399330874" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2023 06:05:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10645"; a="677823873" X-IronPort-AV: E=Sophos;i="5.98,249,1673942400"; d="scan'208";a="677823873" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orsmga002.jf.intel.com with ESMTP; 10 Mar 2023 06:05:24 -0800 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Russ Weight , Luis Chamberlain , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Cezary Rojewski , "Rafael J . Wysocki" , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= Subject: [PATCH v4] firmware_loader: Add debug message with checksum for FW file Date: Fri, 10 Mar 2023 15:04:59 +0100 Message-Id: <20230310140459.2972793-1-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759252959479245031?= X-GMAIL-MSGID: =?utf-8?q?1759996701312653890?= Enable dynamic-debug logging of firmware filenames and SHA256 checksums to clearly identify the firmware files that are loaded by the system. Example output: [ 34.944619] firmware_class:_request_firmware: i915 0000:00:02.0: Loaded FW: i915/kbl_dmc_ver1_04.bin, sha256: 2cde41c3e5ad181423bcc3e98ff9c49f743c88f18646af4d0b3c3a9664b831a1 [ 48.155884] firmware_class:_request_firmware: snd_soc_avs 0000:00:1f.3: Loaded FW: intel/avs/cnl/dsp_basefw.bin, sha256: 43f6ac1b066e9bd0423d914960fbbdccb391af27d2b1da1085eee3ea8df0f357 [ 49.579540] firmware_class:_request_firmware: snd_soc_avs 0000:00:1f.3: Loaded FW: intel/avs/rt274-tplg.bin, sha256: 4b3580da96dc3d2c443ba20c6728d8b665fceb3ed57223c3a57582bbad8e2413 [ 49.798196] firmware_class:_request_firmware: snd_soc_avs 0000:00:1f.3: Loaded FW: intel/avs/hda-8086280c-tplg.bin, sha256: 5653172579b2be1b51fd69f5cf46e2bac8d63f2a1327924311c13b2f1fe6e601 [ 49.859627] firmware_class:_request_firmware: snd_soc_avs 0000:00:1f.3: Loaded FW: intel/avs/dmic-tplg.bin, sha256: 00fb7fbdb74683333400d7e46925dae60db448b88638efcca0b30215db9df63f Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński Reviewed-by: Russ Weight --- Changes in v4: * update menuconfig prompt and help message (Russ) Changes in v3: * add DYNAMIC_DEBUG and FW_LOADER as dependencies before option can be enabled (kernel test robot) Changes in v2: * allocate buffers (Greg) * introduce CONFIG_ option to allow for CONFIG_CRYPTO and CONFIG_CRYPTO_SHA256 dependencies without introducing circular dependency (Greg) * add new line between includes and function name (Cezary) --- drivers/base/firmware_loader/Kconfig | 13 ++++++++ drivers/base/firmware_loader/main.c | 48 +++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig index 5166b323a0f8..6520e8c9cb38 100644 --- a/drivers/base/firmware_loader/Kconfig +++ b/drivers/base/firmware_loader/Kconfig @@ -3,6 +3,7 @@ menu "Firmware loader" config FW_LOADER tristate "Firmware loading facility" if EXPERT + select FW_LOADER_DEBUG if DYNAMIC_DEBUG default y help This enables the firmware loading facility in the kernel. The kernel @@ -24,6 +25,18 @@ config FW_LOADER You also want to be sure to enable this built-in if you are going to enable built-in firmware (CONFIG_EXTRA_FIRMWARE). +config FW_LOADER_DEBUG + bool "Log filenames and checksums for loaded firmware" + depends on DYNAMIC_DEBUG + depends on FW_LOADER + depends on CRYPTO + depends on CRYPTO_SHA256 + default FW_LOADER + help + Select this option to use dynamic debug to log firmware filenames and + SHA256 checksums to the kernel log for each firmware file that is + loaded. + if FW_LOADER config FW_LOADER_PAGED_BUF diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index 017c4cdb219e..b2c292ca95e8 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -791,6 +791,50 @@ static void fw_abort_batch_reqs(struct firmware *fw) mutex_unlock(&fw_lock); } +#if defined(CONFIG_FW_LOADER_DEBUG) +#include +#include + +static void fw_log_firmware_info(const struct firmware *fw, const char *name, struct device *device) +{ + struct shash_desc *shash; + struct crypto_shash *alg; + u8 *sha256buf; + char *outbuf; + + alg = crypto_alloc_shash("sha256", 0, 0); + if (!alg) + return; + + sha256buf = kmalloc(SHA256_DIGEST_SIZE, GFP_KERNEL); + outbuf = kmalloc(SHA256_BLOCK_SIZE + 1, GFP_KERNEL); + shash = kmalloc(sizeof(*shash) + crypto_shash_descsize(alg), GFP_KERNEL); + if (!sha256buf || !outbuf || !shash) + goto out_free; + + shash->tfm = alg; + + if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0) + goto out_shash; + + for (int i = 0; i < SHA256_DIGEST_SIZE; i++) + sprintf(&outbuf[i * 2], "%02x", sha256buf[i]); + outbuf[SHA256_BLOCK_SIZE] = 0; + dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf); + +out_shash: + crypto_free_shash(alg); +out_free: + kfree(shash); + kfree(outbuf); + kfree(sha256buf); +} +#else +static void fw_log_firmware_info(const struct firmware *fw, const char *name, + struct device *device) +{} +#endif + /* called from request_firmware() and request_firmware_work_func() */ static int _request_firmware(const struct firmware **firmware_p, const char *name, @@ -861,11 +905,13 @@ _request_firmware(const struct firmware **firmware_p, const char *name, revert_creds(old_cred); put_cred(kern_cred); - out: +out: if (ret < 0) { fw_abort_batch_reqs(fw); release_firmware(fw); fw = NULL; + } else { + fw_log_firmware_info(fw, name, device); } *firmware_p = fw;