From patchwork Fri Mar 17 22:47:29 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: 71302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp384679wrt; Fri, 17 Mar 2023 07:55:37 -0700 (PDT) X-Google-Smtp-Source: AK7set9wQ4WnwrXyebfMQfM9Ztsm+b7tpIp1R4/3SxveYKm8Nj5bL41V3nNfCNpEmzDZGx5VGYHY X-Received: by 2002:a17:90b:291:b0:23f:3b90:8bd7 with SMTP id az17-20020a17090b029100b0023f3b908bd7mr4669610pjb.1.1679064937713; Fri, 17 Mar 2023 07:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679064937; cv=none; d=google.com; s=arc-20160816; b=X+JpZ8XNVUsKeAuxEQHvkONhtw4tIB5JZPnl284JUtFgzU0CtlFEprhEefhPZoN/6q wc29BpS02dXQi1utMQMkGRcLVBp9W0ODVpS9MVgBjDfN7IA45XqgLXJGO/lybD0SwSpQ H8femaPjH0BZvbZLN4UQLvJKdIG4tYokW2hwkbv93EyuBFugp62sOxCNrE8SpTr1UnM/ p/LKAcZYr0rSAFDhi8zwNI0ekaDghQHpdnq0Ot0T9bwuClJ/TMfvt5gS3+QvuVAxNMpr Rcz1ZjgBM8xwIhwTmVyns7YzGsWpWUB9HpYjokRz2Yef+GYWNfK1iYr2wtCIUznehjLG 9aBg== 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=e3wymgiqnTDFaHO8oMx1srRC+hSw3RX/WrIptMYItHU=; b=Z/KbXDNQ2QLsc5yFS5dM21Dxw3ZTPf/4GqR1K+AddpUNWetsMssCVXq1qjxW1LmRmx Jm+gyoQyhBeeX9ht/pMV2ZyUho96UCiChy4P1wF4Y8zk0UMQz11L73RTfVYy9xI54bHG tgMBsEOZV9bthiFb1hJcvgux9JlDIv5qAMcY9/Mpjh9tI7Ko1WBDLGSVfBhfL8cJNpON b/hsfQ40VCMqWdZfrry4k/B/XmoYoN0eriyCnwicRAtNd5rE86dJknCyrNxYh3G6DDSq jE0baJbQ47oXPAF8jUx7Nea7wcY3g/oljWzCULmYPIkL0BkX/+BIsmxH9bI5Pakf+BxC SSvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Jkhsfyh+; 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 r15-20020a17090a560f00b0023747b030e7si2356264pjf.105.2023.03.17.07.55.22; Fri, 17 Mar 2023 07:55:37 -0700 (PDT) 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=Jkhsfyh+; 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 S231236AbjCQOq1 (ORCPT + 99 others); Fri, 17 Mar 2023 10:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231251AbjCQOqZ (ORCPT ); Fri, 17 Mar 2023 10:46:25 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DACF23847 for ; Fri, 17 Mar 2023 07:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679064384; x=1710600384; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=zpAUeRTWqprtvD9qo8Brjy+2IgyFvWtAe6wwQgE/ZWk=; b=Jkhsfyh+FYkNiOinlLL7lB7YqarAnC3CdL903KS341wEugunsNI/+Qa5 cAWgXQBG70Acg8myMfi9ZkueI3tWDqGdFO3vR3vFz5VYhVgeAWnQ6bNck Keu2q9dOnAMeFAvs9Z7Jmpe8a8E/NlciG1VSJHnWlrr/hYHeTU0EKVgxB 28gU0qMXF7MgzNk4Xm3N0JxSmYdD3eDMqgYyW+opo+0WMWPDVDKyIHM2n 6I1sd1rz1dncrRUby+gA+8POkHCk3GsNsJOJvT8OpnxiJh4RhOxl0GSY8 Xjc2OQKJKh4ZydnnCUGzEPkDQQA6RnooJNNUyFF1S6/slRjmqrnRzwxy/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10652"; a="365974223" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="365974223" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2023 07:46:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10652"; a="823685413" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="823685413" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by fmsmga001.fm.intel.com with ESMTP; 17 Mar 2023 07:46:22 -0700 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 v5] firmware_loader: Add debug message with checksum for FW file Date: Fri, 17 Mar 2023 23:47:29 +0100 Message-Id: <20230317224729.1025879-1-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1760627195883398716?= X-GMAIL-MSGID: =?utf-8?q?1760627195883398716?= 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 Reviewed-by: Russ Weight Signed-off-by: Amadeusz Sławiński --- Changes in v5: * remove unnecessary select in Kconfig (Greg) 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 | 12 +++++++ drivers/base/firmware_loader/main.c | 48 +++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig index 5166b323a0f8..0cabc783d67a 100644 --- a/drivers/base/firmware_loader/Kconfig +++ b/drivers/base/firmware_loader/Kconfig @@ -24,6 +24,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;