From patchwork Fri Sep 17 18:22:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502859 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B7800C433FE for ; Fri, 17 Sep 2021 18:22:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97F036121F for ; Fri, 17 Sep 2021 18:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344533AbhIQSYR (ORCPT ); Fri, 17 Sep 2021 14:24:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344400AbhIQSYK (ORCPT ); Fri, 17 Sep 2021 14:24:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B44EC061574; Fri, 17 Sep 2021 11:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=TpWhHDdGVfR6RDYKOLjBIoqQ9UQe+x0mjeEQUKQ9/JM=; b=S+S6gIrumrtOg4NhyFQ271dZdr Ad/Ojk1EIqWUhRyG4pEowOeFSc09IYoYOdr6Ifq/RicwitFYjRS/qnK/kz1b+GQ3Zp+2BI4ZLKYGu 9o4lyOYtupqQnu8zmWePvOpRjpVfOB+9AK5fU044V2DF4oLutNlxUpG0qAWMBpIpoahUztQatvLdJ 0crirmh6RRhAPUe63SEsrjBp2P/ROCkGnoOOmK7YT5grfHMS6RrVyWRlIRvHyUEevaGGH+2mMg142 VcJO1lTEYnjVJObQ9PINBQi+t676d2Kd9O0mUSooqfv5jaH8jxuGTUKJXc4O/9zh9G1vdRzSgcHkw WRt1ZY9A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5Q-0I; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 01/14] firmware_loader: fix pre-allocated buf built-in firmware use Date: Fri, 17 Sep 2021 11:22:13 -0700 Message-Id: <20210917182226.3532898-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain The firmware_loader can be used with a pre-allocated buffer through the use of the API calls: o request_firmware_into_buf() o request_partial_firmware_into_buf() If the firmware was built-in and present, our current check for if the built-in firmware fits into the pre-allocated buffer does not return any errors, and we proceed to tell the caller that everything worked fine. It's a lie and no firmware would end up being copied into the pre-allocated buffer. So if the caller trust the result it may end up writing a bunch of 0's to a device! Fix this by making the function that checks for the pre-allocated buffer return non-void. Since the typical use case is when no pre-allocated buffer is provided make this return successfully for that case. If the built-in firmware does *not* fit into the pre-allocated buffer size return a failure as we should have been doing before. I'm not aware of users of the built-in firmware using the API calls with a pre-allocated buffer, as such I doubt this fixes any real life issue. But you never know... perhaps some oddball private tree might use it. In so far as upstream is concerned this just fixes our code for correctness. Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index bdbedc6660a8..ef904b8b112e 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -100,12 +100,15 @@ static struct firmware_cache fw_cache; extern struct builtin_fw __start_builtin_fw[]; extern struct builtin_fw __end_builtin_fw[]; -static void fw_copy_to_prealloc_buf(struct firmware *fw, +static bool fw_copy_to_prealloc_buf(struct firmware *fw, void *buf, size_t size) { - if (!buf || size < fw->size) - return; + if (!buf) + return true; + if (size < fw->size) + return false; memcpy(buf, fw->data, fw->size); + return true; } static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, @@ -117,9 +120,7 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, if (strcmp(name, b_fw->name) == 0) { fw->size = b_fw->size; fw->data = b_fw->data; - fw_copy_to_prealloc_buf(fw, buf, size); - - return true; + return fw_copy_to_prealloc_buf(fw, buf, size); } } From patchwork Fri Sep 17 18:22:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502857 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 D00DAC433F5 for ; Fri, 17 Sep 2021 18:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAD5B6121F for ; Fri, 17 Sep 2021 18:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344445AbhIQSYO (ORCPT ); Fri, 17 Sep 2021 14:24:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344382AbhIQSYJ (ORCPT ); Fri, 17 Sep 2021 14:24:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F28CAC061757; Fri, 17 Sep 2021 11:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=mKzIRlwB1vttNdxDwilSgA4QCORfxzhGeRWQQTM2hHY=; b=Jqz9nxvGRM6kbFIYuCNUdRqhKM PWUbRkX+hRjiQ98/k5/NVzHov8XkBj9gkoDGMpntd1lYRAw8Hxgx/Pe8cm/zV+DyG/BUChfF7RvkY O5uft/Wpt6ytZMTZm2DQYT/Jd9fLcjb6/1JzGnPcgEBBgeWNheUn8aPhkDqlbUkEOzvpfclVa0Iby oQ2HE2jREcrQ3KrccbuvhjNo58wA9/pUOtMvlqQ/+14VJWd88e2PyC/MK/asPxt0jVETElr/jNQ8x i79GK+d0xZ7H8woZXhoVPxo9wxSbpQRiKxGP6qk5+qKnNiyR2HNaJxw+vWoBzljsWeNh5pA+lP/BO XvUeVXmg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5S-2r; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 02/14] firmware_loader: split built-in firmware call Date: Fri, 17 Sep 2021 11:22:14 -0700 Message-Id: <20210917182226.3532898-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain There are two ways the firmware_loader can use the built-in firmware: with or without the pre-allocated buffer. We already have one explicit use case for each of these, and so split them up so that it is clear what the intention is on the caller side. This also paves the way so that eventually other callers outside of the firmware loader can uses these if and when needed. While at it, adopt the firmware prefix for the routine names. Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/main.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index ef904b8b112e..eb4085b92ad4 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -111,8 +111,7 @@ static bool fw_copy_to_prealloc_buf(struct firmware *fw, return true; } -static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, - void *buf, size_t size) +static bool firmware_request_builtin(struct firmware *fw, const char *name) { struct builtin_fw *b_fw; @@ -120,13 +119,21 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, if (strcmp(name, b_fw->name) == 0) { fw->size = b_fw->size; fw->data = b_fw->data; - return fw_copy_to_prealloc_buf(fw, buf, size); + return true; } } return false; } +static bool firmware_request_builtin_buf(struct firmware *fw, const char *name, + void *buf, size_t size) +{ + if (!firmware_request_builtin(fw, name)) + return false; + return fw_copy_to_prealloc_buf(fw, buf, size); +} + static bool fw_is_builtin_firmware(const struct firmware *fw) { struct builtin_fw *b_fw; @@ -140,9 +147,15 @@ static bool fw_is_builtin_firmware(const struct firmware *fw) #else /* Module case - no builtin firmware support */ -static inline bool fw_get_builtin_firmware(struct firmware *fw, - const char *name, void *buf, - size_t size) +static inline bool firmware_request_builtin(struct firmware *fw, + const char *name) +{ + return false; +} + +static inline bool firmware_request_builtin_buf(struct firmware *fw, + const char *name, void *buf, + size_t size) { return false; } @@ -737,7 +750,7 @@ _request_firmware_prepare(struct firmware **firmware_p, const char *name, return -ENOMEM; } - if (fw_get_builtin_firmware(firmware, name, dbuf, size)) { + if (firmware_request_builtin_buf(firmware, name, dbuf, size)) { dev_dbg(device, "using built-in %s\n", name); return 0; /* assigned */ } @@ -1216,7 +1229,7 @@ static int uncache_firmware(const char *fw_name) pr_debug("%s: %s\n", __func__, fw_name); - if (fw_get_builtin_firmware(&fw, fw_name, NULL, 0)) + if (firmware_request_builtin(&fw, fw_name)) return 0; fw_priv = lookup_fw_priv(fw_name); From patchwork Fri Sep 17 18:22:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502869 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 65F11C433FE for ; Fri, 17 Sep 2021 18:23:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53C3561244 for ; Fri, 17 Sep 2021 18:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344476AbhIQSYP (ORCPT ); Fri, 17 Sep 2021 14:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344381AbhIQSYJ (ORCPT ); Fri, 17 Sep 2021 14:24:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D90DDC061574; Fri, 17 Sep 2021 11:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=OQG1Hx1C3V+AIbyqDjpSPSWFykzcTbz1vVVOQjeWO0w=; b=Kqb3vawGdf5WUfPAXE1WjKV0Np ST2UiWGAquVxLai4MtQ5hUkWtem+YnCJVFTZDcf64i2zFReePkjpahU7PkXcGIq1RlLrw+Wv6YAtw eJg4vqto+NN3/mbkLvg6wxqUln2hBsZ1I6KmTaDRqUtva3VshG5w4R+ZUNkeGgAmkdrEtSkFQqmG1 5UTWiDuenVQ1S/yiMP3HCKsy3cE22NQQcVCxcMfna5tA2lLagNU3ydUiIBD95s/n8wEoL6Eklhw2i 8tC95HQNppTtqXsl1GNKtgNc+ND/waHTaJyaMT8hI2qB/2BC1jqNyE+NVaNNum8ARRg78y4zj9wMY s+O4gRXg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5U-5G; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 03/14] firmware_loader: add a sanity check for firmware_request_builtin() Date: Fri, 17 Sep 2021 11:22:15 -0700 Message-Id: <20210917182226.3532898-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Right now firmware_request_builtin() is used internally only and so we have control over the callers. But if we want to expose that API more broadly we should ensure the firmware pointer is valid. This doesn't fix any known issue, it just prepares us to later expose this API to other users. Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index eb4085b92ad4..d95b5fe5f700 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -115,6 +115,9 @@ static bool firmware_request_builtin(struct firmware *fw, const char *name) { struct builtin_fw *b_fw; + if (!fw) + return false; + for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { if (strcmp(name, b_fw->name) == 0) { fw->size = b_fw->size; From patchwork Fri Sep 17 18:22:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502867 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 CB8C9C433EF for ; Fri, 17 Sep 2021 18:23:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA9DB611C4 for ; Fri, 17 Sep 2021 18:23:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344532AbhIQSYc (ORCPT ); Fri, 17 Sep 2021 14:24:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344524AbhIQSYR (ORCPT ); Fri, 17 Sep 2021 14:24:17 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C594EC061768; Fri, 17 Sep 2021 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Iu5EEZjwltqs2N860TioX8KgIjxPxn8KDGVoWqpsxrA=; b=p6Kb4Ueij1g/DmufXMCh5opuW5 hLt53u40jBqA8WAO9H2CPW2ZsMM5h9PlXtyx3kiOSpw/eRih/Hq31NeXxgq9CtTygqMGUKeWOH02j AcOokCGQZnSqwi2pNxy45Eer8IV/B6+k4MnzO5eiALLSI1Re38irsl2pVHcAJs/pCEuZYIDf8LZKP EY2Ok9d7TdtvfxtZeTXqbzy11PMClGEch4XKOD0hOCeKNYKKlMQF9EE/q+K/z/ADwcMyJTO9XifIc OGY4vqdG7WtkUOn6Q+lm+B6GVuG3DZtJ9+ek8hiRET9NUYJZ7/Zi/MN94+J0nWstS64DmVL2/Gofm pzQe+08Q==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5W-7c; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 04/14] firmware_loader: add built-in firmware kconfig entry Date: Fri, 17 Sep 2021 11:22:16 -0700 Message-Id: <20210917182226.3532898-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain The built-in firmware is always supported when a user enables FW_LOADER=y today, that is, it is built-in to the kernel. When the firmware loader is built as a module, support for built-in firmware is skipped. This requirement is not really clear to users or even developers. Also, by default the EXTRA_FIRMWARE is always set to an empty string and so by default we really have nothing built-in to that kernel's sections for built-in firmware, so today a all FW_LOADER=y kernels spins their wheels on an empty set of built-in firmware for each firmware request with no true need for it. Add a new kconfig entry to represent built-in firmware support more clearly. This let's knock 3 birds with one stone: o Clarifies that support for built-in firmware requires the firmware loader to be built-in to the kernel o By default we now always skip built-in firmware even if a FW_LOADER=y o This also lets us make it clear that the EXTRA_FIRMWARE_DIR kconfig entry is only used for built-in firmware Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- .../driver-api/firmware/built-in-fw.rst | 2 ++ Documentation/x86/microcode.rst | 5 ++-- drivers/base/firmware_loader/Kconfig | 25 +++++++++++++------ drivers/base/firmware_loader/Makefile | 3 +-- drivers/base/firmware_loader/main.c | 4 +-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Documentation/driver-api/firmware/built-in-fw.rst b/Documentation/driver-api/firmware/built-in-fw.rst index bc1c961bace1..9dd2b1df44f0 100644 --- a/Documentation/driver-api/firmware/built-in-fw.rst +++ b/Documentation/driver-api/firmware/built-in-fw.rst @@ -8,6 +8,7 @@ the filesystem. Instead, firmware can be looked for inside the kernel directly. You can enable built-in firmware using the kernel configuration options: + * CONFIG_FW_LOADER_BUILTIN * CONFIG_EXTRA_FIRMWARE * CONFIG_EXTRA_FIRMWARE_DIR @@ -17,6 +18,7 @@ into the kernel with CONFIG_EXTRA_FIRMWARE: * Speed * Firmware is needed for accessing the boot device, and the user doesn't want to stuff the firmware into the boot initramfs. +* Testing built-in firmware Even if you have these needs there are a few reasons why you may not be able to make use of built-in firmware: diff --git a/Documentation/x86/microcode.rst b/Documentation/x86/microcode.rst index a320d37982ed..d199f0b98869 100644 --- a/Documentation/x86/microcode.rst +++ b/Documentation/x86/microcode.rst @@ -114,11 +114,12 @@ Builtin microcode ================= The loader supports also loading of a builtin microcode supplied through -the regular builtin firmware method CONFIG_EXTRA_FIRMWARE. Only 64-bit is -currently supported. +the regular builtin firmware method using CONFIG_FW_LOADER_BUILTIN and +CONFIG_EXTRA_FIRMWARE. Only 64-bit is currently supported. Here's an example:: + CONFIG_FW_LOADER_BUILTIN=y CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin" CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware" diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig index 5b24f3959255..de4fcd9d41f3 100644 --- a/drivers/base/firmware_loader/Kconfig +++ b/drivers/base/firmware_loader/Kconfig @@ -29,8 +29,10 @@ if FW_LOADER config FW_LOADER_PAGED_BUF bool -config EXTRA_FIRMWARE - string "Build named firmware blobs into the kernel binary" +config FW_LOADER_BUILTIN + bool "Enable support for built-in firmware" + default n + depends on FW_LOADER=y help Device drivers which require firmware can typically deal with having the kernel load firmware from the various supported @@ -43,7 +45,14 @@ config EXTRA_FIRMWARE in boot and cannot rely on the firmware being placed in an initrd or initramfs. - This option is a string and takes the (space-separated) names of the + Support for built-in firmware is not supported if you are using + the firmware loader as a module. + +config EXTRA_FIRMWARE + string "Build named firmware blobs into the kernel binary" + depends on FW_LOADER_BUILTIN + help + This option is a string and takes the space-separated names of the firmware files -- the same names that appear in MODULE_FIRMWARE() and request_firmware() in the source. These files should exist under the directory specified by the EXTRA_FIRMWARE_DIR option, which is @@ -61,12 +70,14 @@ config EXTRA_FIRMWARE consult a lawyer of your own before distributing such an image. config EXTRA_FIRMWARE_DIR - string "Firmware blobs root directory" - depends on EXTRA_FIRMWARE != "" + string "Directory with firmware to be built-in to the kernel" + depends on FW_LOADER_BUILTIN default "/lib/firmware" help - This option controls the directory in which the kernel build system - looks for the firmware files listed in the EXTRA_FIRMWARE option. + This option specifies the directory which the kernel build system + will use to look for the firmware files which are going to be + built into the kernel using the space-separated EXTRA_FIRMWARE + entries. config FW_LOADER_USER_HELPER bool "Enable the firmware sysfs fallback mechanism" diff --git a/drivers/base/firmware_loader/Makefile b/drivers/base/firmware_loader/Makefile index e87843408fe6..a2dbfa19201c 100644 --- a/drivers/base/firmware_loader/Makefile +++ b/drivers/base/firmware_loader/Makefile @@ -1,10 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for the Linux firmware loader +obj-$(CONFIG_FW_LOADER_BUILTIN) += builtin/ obj-$(CONFIG_FW_LOADER_USER_HELPER) += fallback_table.o obj-$(CONFIG_FW_LOADER) += firmware_class.o firmware_class-objs := main.o firmware_class-$(CONFIG_FW_LOADER_USER_HELPER) += fallback.o firmware_class-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += fallback_platform.o - -obj-y += builtin/ diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index d95b5fe5f700..45075c7f9290 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -95,7 +95,7 @@ static struct firmware_cache fw_cache; /* Builtin firmware support */ -#ifdef CONFIG_FW_LOADER +#ifdef CONFIG_FW_LOADER_BUILTIN extern struct builtin_fw __start_builtin_fw[]; extern struct builtin_fw __end_builtin_fw[]; @@ -148,7 +148,7 @@ static bool fw_is_builtin_firmware(const struct firmware *fw) return false; } -#else /* Module case - no builtin firmware support */ +#else static inline bool firmware_request_builtin(struct firmware *fw, const char *name) From patchwork Fri Sep 17 18:22:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502879 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 BD3CAC433FE for ; Fri, 17 Sep 2021 18:23:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A77D36121F for ; Fri, 17 Sep 2021 18:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344632AbhIQSYv (ORCPT ); Fri, 17 Sep 2021 14:24:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244170AbhIQSYM (ORCPT ); Fri, 17 Sep 2021 14:24:12 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC9FC061757; Fri, 17 Sep 2021 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=+bAxPNXEkjOLG0J16lJ79/BZjrPhBIO0OVG4jkta3IU=; b=0iVI7z+X129Mv0/pbPx3RKPj/k hxZMBYWuTcr10TBXzIXvlSWek7JhKLJexctVeUzwzM00et4epv9Nqv9BJ7bak9Z8H7tBFuHDCcoyw EWdX4D1o6FPa0MLP82YVOLadoF9RIM4LfNMRDL7twHJaB+os60U/5GYRiIl2V559w8p2Wl0SkVWJE aJLRFTuPo2U/barhlN8MsMRMLrWHYLiO7g4Nb4QDyaQIgCnWyFCMzfh1gP4vV6GaR0durL++P8I1K NzR2JlKf4klU/brjqKaI0qMCV/O22IaNfuYIMKWxZLc3OfKiPcqwcxRqrcdnoKYvivJVgC+dg2K7c W4BwdnGw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5Y-AF; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 05/14] firmware_loader: formalize built-in firmware API Date: Fri, 17 Sep 2021 11:22:17 -0700 Message-Id: <20210917182226.3532898-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Now that we have a kconfig entry to represent built-in firmware support, formalize its use with a proper API. This can later be used by other callers where all they need is built-in firmware. We export the firmware_request_builtin() call for now only under the TEST_FIRMWARE symbol namespace as there are no direct modular users for it. If they pop up they are free to export it generally. Built-in code always gets access to the callers and we'll demonstrate a hidden user which has been lurking in the kernel for a while and the reason why using a proper API was better long term. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/builtin/Makefile | 6 +- drivers/base/firmware_loader/builtin/main.c | 95 +++++++++++++++++++ drivers/base/firmware_loader/firmware.h | 17 ++++ drivers/base/firmware_loader/main.c | 78 +-------------- include/linux/firmware.h | 11 +++ 5 files changed, 128 insertions(+), 79 deletions(-) create mode 100644 drivers/base/firmware_loader/builtin/main.c diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile index 101754ad48d9..eb4be452062a 100644 --- a/drivers/base/firmware_loader/builtin/Makefile +++ b/drivers/base/firmware_loader/builtin/Makefile @@ -1,11 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 +obj-y += main.o # Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a # leading /, it's relative to $(srctree). fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR)) fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) -obj-y := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))) +firmware := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))) +obj-y += $(firmware) FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) FWSTR = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))) @@ -34,7 +36,7 @@ $(obj)/%.gen.S: FORCE $(call filechk,fwbin) # The .o files depend on the binaries directly; the .S files don't. -$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/% +$(addprefix $(obj)/, $(firmware)): $(obj)/%.gen.o: $(fwdir)/% targets := $(patsubst $(obj)/%,%, \ $(shell find $(obj) -name \*.gen.S 2>/dev/null)) diff --git a/drivers/base/firmware_loader/builtin/main.c b/drivers/base/firmware_loader/builtin/main.c new file mode 100644 index 000000000000..2af0e58f3f9f --- /dev/null +++ b/drivers/base/firmware_loader/builtin/main.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Builtin firmware support */ + +#include +#include "../firmware.h" + +extern struct builtin_fw __start_builtin_fw[]; +extern struct builtin_fw __end_builtin_fw[]; + +static bool fw_copy_to_prealloc_buf(struct firmware *fw, + void *buf, size_t size) +{ + if (!buf) + return true; + if (size < fw->size) + return false; + memcpy(buf, fw->data, fw->size); + return true; +} + +/** + * firmware_request_builtin() - load builtin firmware + * @fw: pointer to firmware struct + * @name: name of firmware file + * + * Some use cases in the kernel have a requirement so that no memory allocator + * is involved as these calls take place early in boot process. An example is + * the x86 CPU microcode loader. In these cases all the caller wants is to see + * if the firmware was built-in and if so use it right away. This can be used + * for such cases. + * + * This looks for the firmware in the built-in kernel. Only if the kernel was + * built-in with the firmware you are looking for will this return successfully. + * + * Callers of this API do not need to use release_firmware() as the pointer to + * the firmware is expected to be provided locally on the stack of the caller. + **/ +bool firmware_request_builtin(struct firmware *fw, const char *name) +{ + struct builtin_fw *b_fw; + + if (!fw) + return false; + + for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { + if (strcmp(name, b_fw->name) == 0) { + fw->size = b_fw->size; + fw->data = b_fw->data; + return true; + } + } + + return false; +} +EXPORT_SYMBOL_NS_GPL(firmware_request_builtin, TEST_FIRMWARE); + +/** + * firmware_request_builtin_buf() - load builtin firmware into optional buffer + * @fw: pointer to firmware struct + * @name: name of firmware file + * @buf: If set this lets you use a pre-allocated buffer so that the built-in + * firmware into is copied into. This field can be NULL. It is used by + * callers such as request_firmware_into_buf() and + * request_partial_firmware_into_buf() + * @size: if buf was provided, the max size of the allocated buffer available. + * If the built-in firmware does not fit into the pre-allocated @buf this + * call will fail. + * + * This looks for the firmware in the built-in kernel. Only if the kernel was + * built-in with the firmware you are looking for will this call possibly + * succeed. If you passed a @buf the firmware will be copied into it *iff* the + * built-in firmware fits into the pre-allocated buffer size specified in + * @size. + * + * This caller is to be used internally by the firmware_loader only. + **/ +bool firmware_request_builtin_buf(struct firmware *fw, const char *name, + void *buf, size_t size) +{ + if (!firmware_request_builtin(fw, name)) + return false; + + return fw_copy_to_prealloc_buf(fw, buf, size); +} + +bool firmware_is_builtin(const struct firmware *fw) +{ + struct builtin_fw *b_fw; + + for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) + if (fw->data == b_fw->data) + return true; + + return false; +} diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h index a3014e9e2c85..7e38827ad006 100644 --- a/drivers/base/firmware_loader/firmware.h +++ b/drivers/base/firmware_loader/firmware.h @@ -151,6 +151,23 @@ static inline void fw_state_done(struct fw_priv *fw_priv) int assign_fw(struct firmware *fw, struct device *device); +#ifdef CONFIG_FW_LOADER_BUILTIN +bool firmware_is_builtin(const struct firmware *fw); +bool firmware_request_builtin_buf(struct firmware *fw, const char *name, + void *buf, size_t size); +#else +static inline bool firmware_is_builtin(const struct firmware *fw) +{ + return false; +} +static inline bool firmware_request_builtin_buf(struct firmware *fw, + const char *name, + void *buf, size_t size) +{ + return false; +} +#endif + #ifdef CONFIG_FW_LOADER_PAGED_BUF void fw_free_paged_buf(struct fw_priv *fw_priv); int fw_grow_paged_buf(struct fw_priv *fw_priv, int pages_needed); diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index 45075c7f9290..94d1789a233e 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -93,82 +93,6 @@ DEFINE_MUTEX(fw_lock); static struct firmware_cache fw_cache; -/* Builtin firmware support */ - -#ifdef CONFIG_FW_LOADER_BUILTIN - -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; - -static bool fw_copy_to_prealloc_buf(struct firmware *fw, - void *buf, size_t size) -{ - if (!buf) - return true; - if (size < fw->size) - return false; - memcpy(buf, fw->data, fw->size); - return true; -} - -static bool firmware_request_builtin(struct firmware *fw, const char *name) -{ - struct builtin_fw *b_fw; - - if (!fw) - return false; - - for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { - if (strcmp(name, b_fw->name) == 0) { - fw->size = b_fw->size; - fw->data = b_fw->data; - return true; - } - } - - return false; -} - -static bool firmware_request_builtin_buf(struct firmware *fw, const char *name, - void *buf, size_t size) -{ - if (!firmware_request_builtin(fw, name)) - return false; - return fw_copy_to_prealloc_buf(fw, buf, size); -} - -static bool fw_is_builtin_firmware(const struct firmware *fw) -{ - struct builtin_fw *b_fw; - - for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) - if (fw->data == b_fw->data) - return true; - - return false; -} - -#else - -static inline bool firmware_request_builtin(struct firmware *fw, - const char *name) -{ - return false; -} - -static inline bool firmware_request_builtin_buf(struct firmware *fw, - const char *name, void *buf, - size_t size) -{ - return false; -} - -static inline bool fw_is_builtin_firmware(const struct firmware *fw) -{ - return false; -} -#endif - static void fw_state_init(struct fw_priv *fw_priv) { struct fw_state *fw_st = &fw_priv->fw_st; @@ -1068,7 +992,7 @@ EXPORT_SYMBOL(request_partial_firmware_into_buf); void release_firmware(const struct firmware *fw) { if (fw) { - if (!fw_is_builtin_firmware(fw)) + if (!firmware_is_builtin(fw)) firmware_free_data(fw); kfree(fw); } diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 25109192cebe..29d17a05ead6 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -20,12 +20,15 @@ struct firmware { struct module; struct device; +#ifdef CONFIG_FW_LOADER_BUILTIN struct builtin_fw { char *name; void *data; unsigned long size; }; +bool firmware_request_builtin(struct firmware *fw, const char *name); + /* We have to play tricks here much like stringify() to get the __COUNTER__ macro to be expanded as we want it */ #define __fw_concat1(x, y) x##y @@ -38,6 +41,14 @@ struct builtin_fw { static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \ __used __section(".builtin_fw") = { name, blob, size } +#else +static inline bool firmware_request_builtin(struct firmware *fw, + const char *name) +{ + return false; +} +#endif + #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) int request_firmware(const struct firmware **fw, const char *name, struct device *device); From patchwork Fri Sep 17 18:22:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502865 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 9BDB9C433EF for ; Fri, 17 Sep 2021 18:23:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81CA6611C4 for ; Fri, 17 Sep 2021 18:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344501AbhIQSYQ (ORCPT ); Fri, 17 Sep 2021 14:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344380AbhIQSYI (ORCPT ); Fri, 17 Sep 2021 14:24:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75582C061574; Fri, 17 Sep 2021 11:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=C6YoTJio2JJPviAT+lMOgCbn00AxJ3TaPTyT+Yh3YZQ=; b=IJ2JLglUvnZwPSc1ZlUZfS4ioP WK6gyLTep0KUa/QICf09nDXKcUj/SgGm9Ylhy3FFGUsDikQ0H8aW/N53Pj5ZLzIh6QQCapobBK2Id w/6Nah9ZeQTuKdF31UmVgv7RBbmjBb2eVF+RDOvbNPMcgIfDYQnQu0WWCvEnKeFGdkm+dWapYfyZL pKalDwExdpsGsFXIPhGegHY1HXsxPrd7skl24r81GQtIpL85kfIV3Z+glNetfuxVmq5ZItL8MFWso gPigO0vS89t/rPrAiJogD5dpXYxozY6iye4YIloNDOCSG5W7pcy/+D8FkG2m4eVVyy219IQWc8PNo vOMlnY3Q==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5a-D2; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 06/14] firmware_loader: remove old DECLARE_BUILTIN_FIRMWARE() Date: Fri, 17 Sep 2021 11:22:18 -0700 Message-Id: <20210917182226.3532898-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain This was never used upstream. Time to get rid of it. We don't carry around unused baggage. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- include/linux/firmware.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 29d17a05ead6..9f21a0db715f 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -28,19 +28,6 @@ struct builtin_fw { }; bool firmware_request_builtin(struct firmware *fw, const char *name); - -/* We have to play tricks here much like stringify() to get the - __COUNTER__ macro to be expanded as we want it */ -#define __fw_concat1(x, y) x##y -#define __fw_concat(x, y) __fw_concat1(x, y) - -#define DECLARE_BUILTIN_FIRMWARE(name, blob) \ - DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob)) - -#define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \ - static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \ - __used __section(".builtin_fw") = { name, blob, size } - #else static inline bool firmware_request_builtin(struct firmware *fw, const char *name) From patchwork Fri Sep 17 18:22:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502873 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,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 329F6C433FE for ; Fri, 17 Sep 2021 18:23:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2163B61244 for ; Fri, 17 Sep 2021 18:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344863AbhIQSYr (ORCPT ); Fri, 17 Sep 2021 14:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344419AbhIQSYM (ORCPT ); Fri, 17 Sep 2021 14:24:12 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC2EC061766; Fri, 17 Sep 2021 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Sg7U2bCbLjaubYtMWf6IzjmNz2LnCsp1x7XoP4U68JU=; b=zXBs1FkTPjDh+9oydNpR/wx3LF Kl4h+BZBGRqjUxV21pxTQdf7Gl7bViMd/JWBl6nmaAtMjpQV4is87r6qIi17hna0UCf+EH3NznJig eES0pOu4flmAZexpVaedWiWULLFZw3MAE8eSBTMeeoCaQMjtGl8lfT4xsRuhVWCbGXzuJo+G02whB fz3DYktrUwvAXSOcKEoOpDMbW9cOqiRDqRokipGU3d8teG1RrLWpDMKP5nDJo4FhaKA3zxbyu7jtg N5uNIuC5jjEnjkyCGzLRqJDcXBTG9gQ1o/N1HVoizt/bjNRJGBiKZDEDbHHcrf/nsbE5w/CYFaWSA YJxE6R0w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5c-EF; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 07/14] x86/microcode: Use the firmware_loader built-in API Date: Fri, 17 Sep 2021 11:22:19 -0700 Message-Id: <20210917182226.3532898-8-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Borislav Petkov The microcode loader has been looping through __start_builtin_fw down to __end_builtin_fw to look for possibly built-in firmware for microcode updates. Now that the firmware loader code has exported an API for looping through the kernel's built-in firmware section, use it and drop the x86 implementation in favor. Signed-off-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- arch/x86/include/asm/microcode.h | 3 --- arch/x86/kernel/cpu/microcode/amd.c | 14 ++++++++++---- arch/x86/kernel/cpu/microcode/core.c | 17 ----------------- arch/x86/kernel/cpu/microcode/intel.c | 9 ++++++++- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h index ab45a220fac4..d6bfdfb0f0af 100644 --- a/arch/x86/include/asm/microcode.h +++ b/arch/x86/include/asm/microcode.h @@ -130,14 +130,11 @@ static inline unsigned int x86_cpuid_family(void) extern void __init load_ucode_bsp(void); extern void load_ucode_ap(void); void reload_early_microcode(void); -extern bool get_builtin_firmware(struct cpio_data *cd, const char *name); extern bool initrd_gone; #else static inline void __init load_ucode_bsp(void) { } static inline void load_ucode_ap(void) { } static inline void reload_early_microcode(void) { } -static inline bool -get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; } #endif #endif /* _ASM_X86_MICROCODE_H */ diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 3d4a48336084..8b2fcdfa6d31 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -456,17 +456,23 @@ apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_p static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family) { -#ifdef CONFIG_X86_64 char fw_name[36] = "amd-ucode/microcode_amd.bin"; + struct firmware fw; + + if (IS_ENABLED(CONFIG_X86_32)) + return false; if (family >= 0x15) snprintf(fw_name, sizeof(fw_name), "amd-ucode/microcode_amd_fam%.2xh.bin", family); - return get_builtin_firmware(cp, fw_name); -#else + if (firmware_request_builtin(&fw, fw_name)) { + cp->size = fw.size; + cp->data = (void *)fw.data; + return true; + } + return false; -#endif } static void __load_ucode_amd(unsigned int cpuid_1_eax, struct cpio_data *ret) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index efb69be41ab1..f955d25076ba 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -140,23 +140,6 @@ static bool __init check_loader_disabled_bsp(void) return *res; } -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; - -bool get_builtin_firmware(struct cpio_data *cd, const char *name) -{ - struct builtin_fw *b_fw; - - for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { - if (!strcmp(name, b_fw->name)) { - cd->size = b_fw->size; - cd->data = b_fw->data; - return true; - } - } - return false; -} - void __init load_ucode_bsp(void) { unsigned int cpuid_1_eax; diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index 7e8e07bddd5f..d28a9f8f3fec 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -456,6 +456,7 @@ static void save_mc_for_early(struct ucode_cpu_info *uci, u8 *mc, unsigned int s static bool load_builtin_intel_microcode(struct cpio_data *cp) { unsigned int eax = 1, ebx, ecx = 0, edx; + struct firmware fw; char name[30]; if (IS_ENABLED(CONFIG_X86_32)) @@ -466,7 +467,13 @@ static bool load_builtin_intel_microcode(struct cpio_data *cp) sprintf(name, "intel-ucode/%02x-%02x-%02x", x86_family(eax), x86_model(eax), x86_stepping(eax)); - return get_builtin_firmware(cp, name); + if (firmware_request_builtin(&fw, name)) { + cp->size = fw.size; + cp->data = (void *)fw.data; + return true; + } + + return false; } /* From patchwork Fri Sep 17 18:22:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502875 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 3D0C2C433EF for ; Fri, 17 Sep 2021 18:23:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A04961244 for ; Fri, 17 Sep 2021 18:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344540AbhIQSYs (ORCPT ); Fri, 17 Sep 2021 14:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344414AbhIQSYM (ORCPT ); Fri, 17 Sep 2021 14:24:12 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AD25C061764; Fri, 17 Sep 2021 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Go1/KDXYjjqeM5NYs2EPZoks5Gkw4uiCOQWYdQBV8sM=; b=Fb5IllX9BA7pj1gVTNIw6W5co/ OQd2O0dAt7UCsm62uQAc9xNWgZeJQ/28xEBQXfRe/SgtfVBErvF4tG08UL7X+GiE89EXbrV1ABUA9 BzuDymOIrVCQDBOTzth+/kOTEfKqfOuC2JQ8LeDs/rf4oG4v2DQh/ryEfZ2Fd62KpGrmph4eGDDCb 2N3TNzro0xMTYeiNNC3DDs3QMC34zq1IYoPDKFWsi84x04eMx4nft8r/IYUWG5evj9Ck8UW91afly DvD2eFLNd5aZNvSE3zNsUlYLXGtorwWT3vxj1mfBuZRV1ZZNsLZG5kirob4ELhbdpfN6i57TEaYIw CJFvDtDA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5i-Ff; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 08/14] firmware_loader: move struct builtin_fw to the only place used Date: Fri, 17 Sep 2021 11:22:20 -0700 Message-Id: <20210917182226.3532898-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Now that x86 doesn't abuse picking at internals to the firmware loader move out the built-in firmware struct to its only user. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/builtin/main.c | 6 ++++++ include/linux/firmware.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/base/firmware_loader/builtin/main.c b/drivers/base/firmware_loader/builtin/main.c index 2af0e58f3f9f..0c78adb39110 100644 --- a/drivers/base/firmware_loader/builtin/main.c +++ b/drivers/base/firmware_loader/builtin/main.c @@ -4,6 +4,12 @@ #include #include "../firmware.h" +struct builtin_fw { + char *name; + void *data; + unsigned long size; +}; + extern struct builtin_fw __start_builtin_fw[]; extern struct builtin_fw __end_builtin_fw[]; diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 9f21a0db715f..7a948739decd 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -21,12 +21,6 @@ struct module; struct device; #ifdef CONFIG_FW_LOADER_BUILTIN -struct builtin_fw { - char *name; - void *data; - unsigned long size; -}; - bool firmware_request_builtin(struct firmware *fw, const char *name); #else static inline bool firmware_request_builtin(struct firmware *fw, From patchwork Fri Sep 17 18:22:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502863 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 24798C433F5 for ; Fri, 17 Sep 2021 18:23:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1179E61216 for ; Fri, 17 Sep 2021 18:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245344AbhIQSYV (ORCPT ); Fri, 17 Sep 2021 14:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344396AbhIQSYK (ORCPT ); Fri, 17 Sep 2021 14:24:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066EBC061757; Fri, 17 Sep 2021 11:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=djQId+Hd358fYZPiVshZR/SjuQwiN+cHEqKXT2KVm8U=; b=JIZ1rDES3nl1mO2nbMpt4H+HCe iCpmSmDRJRtKo6/uUAuDLPxKtsCecRAtLY6EmfNS9JlvEttwF0bo+TsjlgizO7VRU03F0lBS9wW4e 3O0dVsSsWVSDufjdQUj9aHIVrF6GZvllaBiGNBJx7tH6DmxyMkt0W5hzcjpiiEugsdV663UjAejgQ tBxJtXa23lPOf06paArXukcVp/aWhyQ1jIR34zvkKJLk58jTs9eAdwwZNYIoD/AJnFv9MXquUspRy snWvs1Y6kPl/NIYxcB9+mWURDsnJhn9R9+59Ol4pxTozModHZaHObzlnmhbkl6fUhSBcWwxs5dGXP iM+zbXYA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5k-HN; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 09/14] vmlinux.lds.h: wrap built-in firmware support under its kconfig symbol Date: Fri, 17 Sep 2021 11:22:21 -0700 Message-Id: <20210917182226.3532898-10-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain The firmware loader built-in firmware support now has a kconfig symbol representing support for it. Use that to tuck away the sections for built-in firmware. This ensures no oddball user tries to uses these sections without first enabling FW_LOADER_BUILTIN. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- include/asm-generic/vmlinux.lds.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index f2984af2b85b..322af3d552ae 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -470,13 +470,7 @@ __end_pci_fixups_suspend_late = .; \ } \ \ - /* Built-in firmware blobs */ \ - .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) { \ - __start_builtin_fw = .; \ - KEEP(*(.builtin_fw)) \ - __end_builtin_fw = .; \ - } \ - \ + FW_LOADER_BUILT_IN_DATA \ TRACEDATA \ \ PRINTK_INDEX \ @@ -880,6 +874,18 @@ #define ORC_UNWIND_TABLE #endif +/* Built-in firmware blobs */ +#ifdef CONFIG_FW_LOADER_BUILTIN +#define FW_LOADER_BUILT_IN_DATA \ + .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) { \ + __start_builtin_fw = .; \ + KEEP(*(.builtin_fw)) \ + __end_builtin_fw = .; \ + } +#else +#define FW_LOADER_BUILT_IN_DATA +#endif + #ifdef CONFIG_PM_TRACE #define TRACEDATA \ . = ALIGN(4); \ From patchwork Fri Sep 17 18:22:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502871 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 C38EDC433EF for ; Fri, 17 Sep 2021 18:23:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABF1361241 for ; Fri, 17 Sep 2021 18:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344843AbhIQSYq (ORCPT ); Fri, 17 Sep 2021 14:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344423AbhIQSYN (ORCPT ); Fri, 17 Sep 2021 14:24:13 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D11C061767; Fri, 17 Sep 2021 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Ip6/d0KVA5eLYOz78z8ZvhxQLMpGbc01h5vuLB6lJwU=; b=XDy3LOE+qcr1jRa3cO8f3cX+We I0PJsDXoJ5bfxBw5UYGmyFpaJzcKUp6A/RYLVNfLLGnR833Bx80TUGcGkGuWxAl9FixDCTq96apkg 0j2xcy0BqvuZV1Xw6E1kXNg80vjs8Gir4EOKQOUGLhO5SGld/m8txngmqZXGGfpFRcpTqFvrUl0eE UtVVhjBXbyaPcgKLFkWOmVJNPg75xV17buwsRbEXwBMe0H7MZhcFCKeecKNjWY6fIj6aHXiu9rhIl TOSjDTA2dKaBg3+w/bCoodJGZ2hbYApnE7LMrkb8r9HuvjpVs8SHnp6hZP74L62rLkYPyVehbzoo4 3etjOb3w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5m-Ig; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 10/14] x86/build: Tuck away built-in firmware under its kconfig symbol Date: Fri, 17 Sep 2021 11:22:22 -0700 Message-Id: <20210917182226.3532898-11-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Now that it is clear that built-in firmware is only used when built-in firmware is enabled update x86 relocs to reflect that. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- arch/x86/tools/relocs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 27c82207d387..ab3554d4aa06 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -63,7 +63,9 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = { "(__parainstructions|__alt_instructions)(_end)?|" "(__iommu_table|__apicdrivers|__smp_locks)(_end)?|" "__(start|end)_pci_.*|" +#if CONFIG_FW_LOADER_BUILTIN "__(start|end)_builtin_fw|" +#endif "__(start|stop)___ksymtab(_gpl)?|" "__(start|stop)___kcrctab(_gpl)?|" "__(start|stop)___param|" From patchwork Fri Sep 17 18:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502855 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 E3E41C433F5 for ; Fri, 17 Sep 2021 18:22:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA54661241 for ; Fri, 17 Sep 2021 18:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344413AbhIQSYM (ORCPT ); Fri, 17 Sep 2021 14:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344392AbhIQSYJ (ORCPT ); Fri, 17 Sep 2021 14:24:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D9E9C061574; Fri, 17 Sep 2021 11:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=ZzaciR8ve7n20ZcFiVg0y2XicmgWHcd906Wyz0gIy9E=; b=ES9saNgpa4mxpTW4fopZPPTEuq TBLZkSNA1Y2JPaitz3hisgycOO2BG+UtE6Atni+L4+oVx+1hd15uLGWIVQe8cGDk3K+wX2F5+UuoZ Jo0ru+TofNOCWkO9pRbOr5pyCCOxMTWHUdxIOEHsbA1528nleGhNAs8l7oCl3W1+0Lex2uxGOG7Oa 0wAv5YkO7P4yVdDPXVJRLkhB/Q7T4VmSaQ9czhe/IlS2hyy4xs9PsC/7qvE2OFLswBqEicpQNywkn dOowrt310okeABxDQKUdvjn3qxSt0LTX/0L+9Kz2FoBoZhq0QuCFC751MlW6ziXsHyvdLMTTOLpeL 2nAJglOQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5o-KQ; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 11/14] firmware_loader: rename EXTRA_FIRMWARE and EXTRA_FIRMWARE_DIR Date: Fri, 17 Sep 2021 11:22:23 -0700 Message-Id: <20210917182226.3532898-12-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Now that we've tied loose ends on the built-in firmware API, rename the kconfig symbols for it to reflect more that they are associated to the firmware_loader and to make it easier to understand what they are for. Signed-off-by: Luis Chamberlain --- .../driver-api/firmware/built-in-fw.rst | 6 +++--- Documentation/x86/microcode.rst | 6 +++--- arch/x86/Kconfig | 4 ++-- drivers/base/firmware_loader/Kconfig | 20 +++++++++++-------- drivers/base/firmware_loader/builtin/Makefile | 6 +++--- drivers/staging/media/av7110/Kconfig | 4 ++-- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Documentation/driver-api/firmware/built-in-fw.rst b/Documentation/driver-api/firmware/built-in-fw.rst index 9dd2b1df44f0..b36ea4b13b5e 100644 --- a/Documentation/driver-api/firmware/built-in-fw.rst +++ b/Documentation/driver-api/firmware/built-in-fw.rst @@ -9,11 +9,11 @@ directly. You can enable built-in firmware using the kernel configuration options: * CONFIG_FW_LOADER_BUILTIN - * CONFIG_EXTRA_FIRMWARE - * CONFIG_EXTRA_FIRMWARE_DIR + * CONFIG_FW_LOADER_BUILTIN_FILES + * CONFIG_FW_LOADER_BUILTIN_DIR There are a few reasons why you might want to consider building your firmware -into the kernel with CONFIG_EXTRA_FIRMWARE: +into the kernel with CONFIG_FW_LOADER_BUILTIN_FILES: * Speed * Firmware is needed for accessing the boot device, and the user doesn't diff --git a/Documentation/x86/microcode.rst b/Documentation/x86/microcode.rst index d199f0b98869..7aa9c86b2868 100644 --- a/Documentation/x86/microcode.rst +++ b/Documentation/x86/microcode.rst @@ -115,13 +115,13 @@ Builtin microcode The loader supports also loading of a builtin microcode supplied through the regular builtin firmware method using CONFIG_FW_LOADER_BUILTIN and -CONFIG_EXTRA_FIRMWARE. Only 64-bit is currently supported. +CONFIG_FW_LOADER_BUILTIN_FILES. Only 64-bit is currently supported. Here's an example:: CONFIG_FW_LOADER_BUILTIN=y - CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin" - CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware" + CONFIG_FW_LOADER_BUILTIN_FILES="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin" + CONFIG_FW_LOADER_BUILTIN_DIR="/lib/firmware" This basically means, you have the following tree structure locally:: diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 25960fe242bd..60eae188ebe0 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1304,8 +1304,8 @@ config MICROCODE initrd for microcode blobs. In addition, you can build the microcode into the kernel. For that you - need to add the vendor-supplied microcode to the CONFIG_EXTRA_FIRMWARE - config option. + need to add the vendor-supplied microcode to the configuration option + CONFIG_FW_LOADER_BUILTIN_FILES config MICROCODE_INTEL bool "Intel microcode loading support" diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig index de4fcd9d41f3..181bfbc108e6 100644 --- a/drivers/base/firmware_loader/Kconfig +++ b/drivers/base/firmware_loader/Kconfig @@ -22,7 +22,7 @@ config FW_LOADER You typically want this built-in (=y) but you can also enable this as a module, in which case the firmware_class module will be built. You also want to be sure to enable this built-in if you are going to - enable built-in firmware (CONFIG_EXTRA_FIRMWARE). + enable built-in firmware (CONFIG_FW_LOADER_BUILTIN_FILES). if FW_LOADER @@ -48,18 +48,22 @@ config FW_LOADER_BUILTIN Support for built-in firmware is not supported if you are using the firmware loader as a module. -config EXTRA_FIRMWARE +config FW_LOADER_BUILTIN_FILES string "Build named firmware blobs into the kernel binary" depends on FW_LOADER_BUILTIN help This option is a string and takes the space-separated names of the firmware files -- the same names that appear in MODULE_FIRMWARE() and request_firmware() in the source. These files should exist under - the directory specified by the EXTRA_FIRMWARE_DIR option, which is + the directory specified by the FW_LOADER_BUILTIN_DIR option, which is /lib/firmware by default. - For example, you might set CONFIG_EXTRA_FIRMWARE="usb8388.bin", copy - the usb8388.bin file into /lib/firmware, and build the kernel. Then + For example, you might have set: + + CONFIG_FW_LOADER_BUILTIN_FILES="usb8388.bin" + + After this you would copy the usb8388.bin file into directory + specified by FW_LOADER_BUILTIN_DIR and build the kernel. Then any request_firmware("usb8388.bin") will be satisfied internally inside the kernel without ever looking at your filesystem at runtime. @@ -69,15 +73,15 @@ config EXTRA_FIRMWARE image since it combines both GPL and non-GPL work. You should consult a lawyer of your own before distributing such an image. -config EXTRA_FIRMWARE_DIR +config FW_LOADER_BUILTIN_DIR string "Directory with firmware to be built-in to the kernel" depends on FW_LOADER_BUILTIN default "/lib/firmware" help This option specifies the directory which the kernel build system will use to look for the firmware files which are going to be - built into the kernel using the space-separated EXTRA_FIRMWARE - entries. + built into the kernel using the space-separated + FW_LOADER_BUILTIN_FILES entries. config FW_LOADER_USER_HELPER bool "Enable the firmware sysfs fallback mechanism" diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile index eb4be452062a..7cdd0b5c7384 100644 --- a/drivers/base/firmware_loader/builtin/Makefile +++ b/drivers/base/firmware_loader/builtin/Makefile @@ -1,12 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 obj-y += main.o -# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a +# Create $(fwdir) from $(CONFIG_FW_LOADER_BUILTIN_DIR) -- if it doesn't have a # leading /, it's relative to $(srctree). -fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR)) +fwdir := $(subst $(quote),,$(CONFIG_FW_LOADER_BUILTIN_DIR)) fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) -firmware := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))) +firmware := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_FW_LOADER_BUILTIN_FILES))) obj-y += $(firmware) FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) diff --git a/drivers/staging/media/av7110/Kconfig b/drivers/staging/media/av7110/Kconfig index 9faf9d2d4001..87c7702f72f6 100644 --- a/drivers/staging/media/av7110/Kconfig +++ b/drivers/staging/media/av7110/Kconfig @@ -31,8 +31,8 @@ config DVB_AV7110 or /lib/firmware (depending on configuration of firmware hotplug). Alternatively, you can download the file and use the kernel's - EXTRA_FIRMWARE configuration option to build it into your - kernel image by adding the filename to the EXTRA_FIRMWARE + FW_LOADER_BUILTIN_FILES configuration option to build it into your + kernel image by adding the filename to the FW_LOADER_BUILTIN_FILES configuration option string. Say Y if you own such a card and want to use it. From patchwork Fri Sep 17 18:22:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502877 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 73958C43217 for ; Fri, 17 Sep 2021 18:23:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D23B611C4 for ; Fri, 17 Sep 2021 18:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344891AbhIQSYt (ORCPT ); Fri, 17 Sep 2021 14:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244038AbhIQSYM (ORCPT ); Fri, 17 Sep 2021 14:24:12 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BF2C061574; Fri, 17 Sep 2021 11:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=vQDziZ7ZyhPvCe5V/cGR0gQ3vb8WJNHnEcQgc70mPbE=; b=ZKs5RNOIEpLWqHseAvqSsPN6TY wl9se0hdkMrYwz5bnT/vyxwRlPi3LDNXURpB9TIQ+fK1yTFhXvsmsgMFoOUILg8+MZoWJxbdlgfFU VKNZOmYtnZm2z2st/ZJcDrqAqx0NoxPPhA9nFlbf2C9k3ChKZItsv/uO5jqwkONh0Pi0PySKePadt AatwMeUpldovVfCiLV80lmA4JrycGUICN69Cffyze3TrpJYwAfeV32CXUHqJHsNN+j2GlSgZ1oSox USrgnZId1AjWX2pppgnkn4gS2IZCjo314uCsGlK+xTqAi8I68mXD4AiHA5wVymGLelWZRLFtxlLhO 2cJ7PYjg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5q-MD; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 12/14] firmware_loader: move builtin build helper to shared library Date: Fri, 17 Sep 2021 11:22:24 -0700 Message-Id: <20210917182226.3532898-13-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain If we wanted to use a different directory for building target builtin firmware it is easier if we just have a shared library Makefile, and each target directory can then just include it and populate the respective needed variables. This reduces clutter, makes things easier to read, and also most importantly allows us to not have to try to magically adjust only one target kconfig symbol for built-in firmware files. Trying to do this can easily end up causing odd build issues if the user is not careful. As an example issue, if we are going to try to extend the FW_LOADER_BUILTIN_FILES list and FW_LOADER_BUILTIN_DIR in case of a new test firmware builtin support currently our only option would be modify the defaults of each of these in case test firmware builtin support was enabled. Defaults however won't augment a prior setting, and so if FW_LOADER_BUILTIN_DIR="/lib/firmware" and you and want this to be changed to something like FW_LOADER_BUILTIN_DIR="drivers/base/firmware_loader/test-builtin" the change will not take effect as a prior build already had it set, and the build would fail. Trying to augment / append the variables in the Makefile just makes this very difficult to read. Using a library let's us split up possible built-in targets so that the user does not have to be involved. This will be used in a subsequent patch which will add another user to this built-in firmware library Makefile and demo how to use it outside of the default FW_LOADER_BUILTIN_DIR and FW_LOADER_BUILTIN_FILES. Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/builtin/Makefile | 34 ++----------------- .../base/firmware_loader/builtin/lib.Makefile | 32 +++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 drivers/base/firmware_loader/builtin/lib.Makefile diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile index 7cdd0b5c7384..9b0dc193f6c7 100644 --- a/drivers/base/firmware_loader/builtin/Makefile +++ b/drivers/base/firmware_loader/builtin/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +include $(srctree)/drivers/base/firmware_loader/builtin/lib.Makefile + obj-y += main.o # Create $(fwdir) from $(CONFIG_FW_LOADER_BUILTIN_DIR) -- if it doesn't have a @@ -8,35 +10,3 @@ fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) firmware := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_FW_LOADER_BUILTIN_FILES))) obj-y += $(firmware) - -FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) -FWSTR = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))) -ASM_WORD = $(if $(CONFIG_64BIT),.quad,.long) -ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) -PROGBITS = $(if $(CONFIG_ARM),%,@)progbits - -filechk_fwbin = \ - echo "/* Generated by $(src)/Makefile */" ;\ - echo " .section .rodata" ;\ - echo " .p2align 4" ;\ - echo "_fw_$(FWSTR)_bin:" ;\ - echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\ - echo "_fw_end:" ;\ - echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\ - echo " .p2align $(ASM_ALIGN)" ;\ - echo "_fw_$(FWSTR)_name:" ;\ - echo " .string \"$(FWNAME)\"" ;\ - echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\ - echo " .p2align $(ASM_ALIGN)" ;\ - echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\ - echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\ - echo " $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin" - -$(obj)/%.gen.S: FORCE - $(call filechk,fwbin) - -# The .o files depend on the binaries directly; the .S files don't. -$(addprefix $(obj)/, $(firmware)): $(obj)/%.gen.o: $(fwdir)/% - -targets := $(patsubst $(obj)/%,%, \ - $(shell find $(obj) -name \*.gen.S 2>/dev/null)) diff --git a/drivers/base/firmware_loader/builtin/lib.Makefile b/drivers/base/firmware_loader/builtin/lib.Makefile new file mode 100644 index 000000000000..e979a67acfa7 --- /dev/null +++ b/drivers/base/firmware_loader/builtin/lib.Makefile @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0 +FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) +FWSTR = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))) +ASM_WORD = $(if $(CONFIG_64BIT),.quad,.long) +ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) +PROGBITS = $(if $(CONFIG_ARM),%,@)progbits + +filechk_fwbin = \ + echo "/* Generated by $(src)/Makefile */" ;\ + echo " .section .rodata" ;\ + echo " .p2align 4" ;\ + echo "_fw_$(FWSTR)_bin:" ;\ + echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\ + echo "_fw_end:" ;\ + echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\ + echo " .p2align $(ASM_ALIGN)" ;\ + echo "_fw_$(FWSTR)_name:" ;\ + echo " .string \"$(FWNAME)\"" ;\ + echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\ + echo " .p2align $(ASM_ALIGN)" ;\ + echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\ + echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\ + echo " $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin" + +$(obj)/%.gen.S: FORCE + $(call filechk,fwbin) + +# The .o files depend on the binaries directly; the .S files don't. +$(addprefix $(obj)/, $(firmware)): $(obj)/%.gen.o: $(fwdir)/% + +targets := $(patsubst $(obj)/%,%, \ + $(shell find $(obj) -name \*.gen.S 2>/dev/null)) From patchwork Fri Sep 17 18:22:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502853 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 9F45AC433FE for ; Fri, 17 Sep 2021 18:22:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7036761353 for ; Fri, 17 Sep 2021 18:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344375AbhIQSYH (ORCPT ); Fri, 17 Sep 2021 14:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234479AbhIQSYG (ORCPT ); Fri, 17 Sep 2021 14:24:06 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2D60C061574; Fri, 17 Sep 2021 11:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=tD4Sbra29CB+zDaId3JKIIubIM6CxINJL6HrVfCbIoA=; b=zkwXatXSLHRehaBwXk1y8v317Y 1UtVMaNO10I3xGAvya1UM6SPveE0FNAH+KI5JrLvVpE9Bs6Cq2Ztb0QcBPOFGVkKzlIhhwOvDVLWy cXZV56xaJpif4DvbrBmFhMyI16m9ZuJbrqfqh4mcUADuQnsItHEnBEupdvizQqsSnoLmQCEsx0kEz R/UjBcBJ3/5mm10KLthGJocfnM7wMqLZkCo3n98IKYEP0Fm7Nwi07cDFzlKHHC7VwKIsy3tz9gUg4 Lj2VAsXzxBFdSxplrjX6Gdo0fBVXi5tGfGzDNfsquHu1vPccfnawu1UIqwMQ4Wdvd+CO1TH0fxLWc LQ4mbEeA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5s-Nq; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 13/14] test_firmware: move a few test knobs out to its library Date: Fri, 17 Sep 2021 11:22:25 -0700 Message-Id: <20210917182226.3532898-14-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain These will be used by other tests cases in other files so move them to the library. Signed-off-by: Luis Chamberlain --- .../testing/selftests/firmware/fw_filesystem.sh | 16 ---------------- tools/testing/selftests/firmware/fw_lib.sh | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh index c2a2a100114b..7d763b303057 100755 --- a/tools/testing/selftests/firmware/fw_filesystem.sh +++ b/tools/testing/selftests/firmware/fw_filesystem.sh @@ -118,27 +118,11 @@ test_config_present() fi } -# Defaults : -# -# send_uevent: 1 -# sync_direct: 0 -# name: test-firmware.bin -# num_requests: 4 -config_reset() -{ - echo 1 > $DIR/reset -} - release_all_firmware() { echo 1 > $DIR/release_all_firmware } -config_set_name() -{ - echo -n $1 > $DIR/config_name -} - config_set_into_buf() { echo 1 > $DIR/config_into_buf diff --git a/tools/testing/selftests/firmware/fw_lib.sh b/tools/testing/selftests/firmware/fw_lib.sh index 5b8c0fedee76..31b71fe11dc5 100755 --- a/tools/testing/selftests/firmware/fw_lib.sh +++ b/tools/testing/selftests/firmware/fw_lib.sh @@ -221,3 +221,20 @@ kconfig_has() fi fi } + +# Defaults : +# +# send_uevent: 1 +# sync_direct: 0 +# name: test-firmware.bin +# num_requests: 4 +config_reset() +{ + echo 1 > $DIR/reset +} + + +config_set_name() +{ + echo -n $1 > $DIR/config_name +} From patchwork Fri Sep 17 18:22:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12502861 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 DD536C433FE for ; Fri, 17 Sep 2021 18:23:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4BCC61216 for ; Fri, 17 Sep 2021 18:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344562AbhIQSYT (ORCPT ); Fri, 17 Sep 2021 14:24:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344385AbhIQSYK (ORCPT ); Fri, 17 Sep 2021 14:24:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E68E2C061574; Fri, 17 Sep 2021 11:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=6neZMk8nIHRa1EIGCZCZEDYnkcLhMWqLQlwommjSFIQ=; b=y8ocI7h2Y0onrMjngauvkQPkC2 8W2o8/SA6bYWACLEyO+f97HX6n+yHiDMexBQmjDshP4Fbpm0j0IsC+oRg3e+4aSkXiNBak/nq4t5+ 311TUeRXhHYHCWmIL99L1Dx1+DvMYOTtfCekDAM83jXzw8dBC+JeCvdk3d3rkVXgQN0N/aheGJjbJ FLFJRf08cl/G62EA0bFWolGnK2rgVKtiVGMnQEqbcAoiElF9SGsdTupk8GZqB3SyfVBBDXTRKchJS 1iQvwShcvrGlAYU9m0Hoo10FqQbUVKxAL9fzWiOE3WFW2nzEOx2FDPEYeH7MWdJsnXYO3ddvQKy// joIotjpg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRIVI-00Ep5u-Pu; Fri, 17 Sep 2021 18:22:28 +0000 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: bp@suse.de, akpm@linux-foundation.org, josh@joshtriplett.org, rishabhb@codeaurora.org, kubakici@wp.pl, maco@android.com, david.brown@linaro.org, bjorn.andersson@linaro.org, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, jewalt@lgsinnovations.com, cantabile.desu@gmail.com, ast@fb.com, andresx7@gmail.com, dan.rue@linaro.org, brendanhiggins@google.com, yzaikin@google.com, sfr@canb.auug.org.au, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 14/14] test_firmware: add support for testing built-in firmware Date: Fri, 17 Sep 2021 11:22:26 -0700 Message-Id: <20210917182226.3532898-15-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917182226.3532898-1-mcgrof@kernel.org> References: <20210917182226.3532898-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain This adds some basic knobs to let us test built-in firmware support. We test to ensure built-in firmware is indeed used, and that it matches the contents we expect. Likewise we test that a file that should not be built-in was not present. For older kernels with older test_firmware drivers (yes some folks do test selftests this way and we support it), the new built-in test will simply bail out early. Reviewed-by: Borislav Petkov Signed-off-by: Luis Chamberlain --- drivers/base/firmware_loader/Makefile | 1 + drivers/base/firmware_loader/builtin/Makefile | 1 + .../firmware_loader/test-builtin/.gitignore | 3 + .../firmware_loader/test-builtin/Makefile | 18 +++++ lib/Kconfig.debug | 34 +++++++++ lib/test_firmware.c | 52 +++++++++++++- .../testing/selftests/firmware/fw_builtin.sh | 69 +++++++++++++++++++ tools/testing/selftests/firmware/fw_lib.sh | 7 ++ .../selftests/firmware/fw_run_tests.sh | 2 + 9 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 drivers/base/firmware_loader/test-builtin/.gitignore create mode 100644 drivers/base/firmware_loader/test-builtin/Makefile create mode 100755 tools/testing/selftests/firmware/fw_builtin.sh diff --git a/drivers/base/firmware_loader/Makefile b/drivers/base/firmware_loader/Makefile index a2dbfa19201c..1f883ea29135 100644 --- a/drivers/base/firmware_loader/Makefile +++ b/drivers/base/firmware_loader/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for the Linux firmware loader +obj-$(CONFIG_TEST_FIRMWARE_BUILTIN) += test-builtin/ obj-$(CONFIG_FW_LOADER_BUILTIN) += builtin/ obj-$(CONFIG_FW_LOADER_USER_HELPER) += fallback_table.o obj-$(CONFIG_FW_LOADER) += firmware_class.o diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile index 9b0dc193f6c7..baad7777974b 100644 --- a/drivers/base/firmware_loader/builtin/Makefile +++ b/drivers/base/firmware_loader/builtin/Makefile @@ -2,6 +2,7 @@ include $(srctree)/drivers/base/firmware_loader/builtin/lib.Makefile obj-y += main.o +obj-$(CONFIG_TEST_BUILTIN_FIRMWARE) += test-builtin-firmware.bin.gen.o # Create $(fwdir) from $(CONFIG_FW_LOADER_BUILTIN_DIR) -- if it doesn't have a # leading /, it's relative to $(srctree). diff --git a/drivers/base/firmware_loader/test-builtin/.gitignore b/drivers/base/firmware_loader/test-builtin/.gitignore new file mode 100644 index 000000000000..1d46553f50a0 --- /dev/null +++ b/drivers/base/firmware_loader/test-builtin/.gitignore @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +*.gen.S +*.bin diff --git a/drivers/base/firmware_loader/test-builtin/Makefile b/drivers/base/firmware_loader/test-builtin/Makefile new file mode 100644 index 000000000000..04204ad7ede1 --- /dev/null +++ b/drivers/base/firmware_loader/test-builtin/Makefile @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 +include $(srctree)/drivers/base/firmware_loader/builtin/lib.Makefile + +extra-y := test-builtin-firmware.bin +$(obj)/test-builtin-firmware.bin: FORCE + @$(kecho) " GEN $@" + @(set -e; \ + ( \ + echo 'ABCD0123'; \ + ) > $@) + +# Create $(fwdir) from $(CONFIG_TEST_FIRMWARE_BUILTIN_DIR) -- if it doesn't +# have a leading /, it's relative to $(srctree). +fwdir := $(subst $(quote),,$(CONFIG_TEST_FIRMWARE_BUILTIN_DIR)) +fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) + +firmware := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_TEST_FIRMWARE_BUILTIN_FILES))) +obj-y += $(firmware) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index b6734839a84a..9a5b6759fc36 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2333,6 +2333,40 @@ config TEST_FIRMWARE If unsure, say N. +config TEST_FIRMWARE_BUILTIN + bool "Allow building built-in test firmware" + depends on TEST_FIRMWARE + select FW_LOADER_BUILTIN + help + If enabled, firmware will be built into to the kernel so that + loading it with the test_firmware driver can be tested. Disabling + this will just mean the test firmware scripts won't find any + built-in firmware. Enabling this will make the kernel generate the + file test-builtin-firmware.bin inside local directory + drivers/base/firmware_loader/test-builtin. This file will then + be available whenever the request firmware API is used. + + Enabling this functionlity essentially overrides the location where + you specify to find built-in firmware, and so should only be enabled + if you don't need to build firmware into your kernel for full + funcionality. + + This should be disabled on production kernels as otherwise you'll + end up with a test firmware stuck into your final kernel image and + with default built-in firmware support. + + If unsure, say N. + +config TEST_FIRMWARE_BUILTIN_FILES + string + depends on TEST_FIRMWARE_BUILTIN + default "test-builtin-firmware.bin" + +config TEST_FIRMWARE_BUILTIN_DIR + string + depends on TEST_FIRMWARE_BUILTIN + default "drivers/base/firmware_loader/test-builtin" + config TEST_SYSCTL tristate "sysctl test driver" depends on PROC_SYSCTL diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 1bccd6cd5f48..134f8c78d2d4 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -34,6 +34,7 @@ MODULE_IMPORT_NS(TEST_FIRMWARE); static DEFINE_MUTEX(test_fw_mutex); static const struct firmware *test_firmware; +static struct firmware builtin_test_firmware; struct test_batched_req { u8 idx; @@ -58,6 +59,10 @@ struct test_batched_req { * @sync_direct: when the sync trigger is used if this is true * request_firmware_direct() will be used instead. * @send_uevent: whether or not to send a uevent for async requests + * @is_builtin: used only internally to determine if the firmware was found + * to be built-in to the kernel using only the API call + * firmware_request_builtin(). We treat this specially as we are + * responsible for the firmware struct. * @num_requests: number of requests to try per test case. This is trigger * specific. * @reqs: stores all requests information @@ -99,6 +104,7 @@ struct test_config { bool partial; bool sync_direct; bool send_uevent; + bool is_builtin; u8 num_requests; u8 read_fw_idx; @@ -120,7 +126,11 @@ static ssize_t test_fw_misc_read(struct file *f, char __user *buf, ssize_t rc = 0; mutex_lock(&test_fw_mutex); - if (test_firmware) + if (test_fw_config->is_builtin) + rc = simple_read_from_buffer(buf, size, offset, + builtin_test_firmware.data, + builtin_test_firmware.size); + else if (test_firmware) rc = simple_read_from_buffer(buf, size, offset, test_firmware->data, test_firmware->size); @@ -194,6 +204,7 @@ static int __test_firmware_config_init(void) test_fw_config->buf_size = TEST_FIRMWARE_BUF_SIZE; test_fw_config->file_offset = 0; test_fw_config->partial = false; + test_fw_config->is_builtin = false; test_fw_config->sync_direct = false; test_fw_config->req_firmware = request_firmware; test_fw_config->test_result = 0; @@ -1051,6 +1062,44 @@ static ssize_t read_firmware_show(struct device *dev, } static DEVICE_ATTR_RO(read_firmware); +/* + * In order to test this, set CONFIG_FW_LOADER_BUILTIN_FILES to a firmware file + * which will be built into the kernel image. Then echo the name into the + * "trigger_request_builtin" sysfs file of this module. + */ +static ssize_t trigger_request_builtin_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int rc = -ENOENT; + + if (!test_fw_config->name) { + pr_warn("unconfigured firmware settings\n"); + return rc; + } + + pr_info("loading builtin '%s'\n", test_fw_config->name); + + mutex_lock(&test_fw_mutex); + + if (firmware_request_builtin(&builtin_test_firmware, + test_fw_config->name)) { + /* This let's us diff against the firmware */ + test_fw_config->is_builtin = true; + pr_info("loaded: %zu\n", builtin_test_firmware.size); + rc = count; + goto out; + } + + pr_info("load of '%s' failed\n", test_fw_config->name); + +out: + mutex_unlock(&test_fw_mutex); + + return rc; +} +static DEVICE_ATTR_WO(trigger_request_builtin); + #define TEST_FW_DEV_ATTR(name) &dev_attr_##name.attr static struct attribute *test_dev_attrs[] = { @@ -1082,6 +1131,7 @@ static struct attribute *test_dev_attrs[] = { TEST_FW_DEV_ATTR(release_all_firmware), TEST_FW_DEV_ATTR(test_result), TEST_FW_DEV_ATTR(read_firmware), + TEST_FW_DEV_ATTR(trigger_request_builtin), NULL, }; diff --git a/tools/testing/selftests/firmware/fw_builtin.sh b/tools/testing/selftests/firmware/fw_builtin.sh new file mode 100755 index 000000000000..44e4198ed88f --- /dev/null +++ b/tools/testing/selftests/firmware/fw_builtin.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Test loading built-in firmware +set -e + +TEST_REQS_FW_SYSFS_FALLBACK="no" +TEST_REQS_FW_SET_CUSTOM_PATH="yes" +TEST_DIR=$(dirname $0) +source $TEST_DIR/fw_lib.sh + +check_mods +check_setup +verify_reqs +setup_tmp_file + +trap "test_finish" EXIT + +if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then + # Turn down the timeout so failures don't take so long. + echo 1 >/sys/class/firmware/timeout +fi + +# built-in firmware support can be optional to test +if [[ "$HAS_FW_LOADER_BUILTIN" != "yes" || "$HAS_TEST_FIRMWARE_BUILTIN" != "yes" ]]; then + exit $ksft_skip +fi + +echo "Testing builtin firmware API ... " + +config_trigger_builtin() +{ + echo -n 1 > $DIR/trigger_request_builtin +} + +test_builtin_firmware() +{ + echo -n "Testing firmware_request_builtin() ... " + config_reset + config_set_name $TEST_FIRMWARE_BUILTIN_FILENAME + config_trigger_builtin + echo OK + # Verify the contents are what we expect. + echo -n "Verifying file integrity ..." + if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then + echo "$0: firmware loaded content differs" >&2 + exit 1 + else + echo "firmware content matches what we expect - OK" + fi +} + +test_builtin_firmware_nofile() +{ + echo -n "Testing firmware_request_builtin() with fake file... " + config_reset + config_set_name fake-${TEST_FIRMWARE_BUILTIN_FILENAME} + if config_trigger_builtin 2> /dev/null; then + echo "$0: firmware shouldn't have loaded" >&2 + fi + echo "OK" +} + +test_builtin_firmware +test_builtin_firmware_nofile + +# Ensure test_fw_config->is_builtin is set back to false +# otherwise we won't be able to diff against the right target +# firmware for other tests. +config_reset diff --git a/tools/testing/selftests/firmware/fw_lib.sh b/tools/testing/selftests/firmware/fw_lib.sh index 31b71fe11dc5..29949e975345 100755 --- a/tools/testing/selftests/firmware/fw_lib.sh +++ b/tools/testing/selftests/firmware/fw_lib.sh @@ -15,6 +15,10 @@ TEST_DIR=$(dirname $0) # To reproduce rename this to test-firmware.bin TEST_FIRMWARE_INTO_BUF_FILENAME=test-firmware-into-buf.bin +# We should use a different filename for built-in firmware otherwise +# we'd always have the file present. +TEST_FIRMWARE_BUILTIN_FILENAME=test-builtin-firmware.bin + # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 @@ -63,6 +67,9 @@ check_setup() HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)" HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)" HAS_FW_LOADER_COMPRESS="$(kconfig_has CONFIG_FW_LOADER_COMPRESS=y)" + HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)" + HAS_FW_LOADER_BUILTIN="$(kconfig_has CONFIG_FW_LOADER_BUILTIN=y)" + HAS_TEST_FIRMWARE_BUILTIN="$(kconfig_has CONFIG_TEST_FIRMWARE_BUILTIN=y)" PROC_FW_IGNORE_SYSFS_FALLBACK="0" PROC_FW_FORCE_SYSFS_FALLBACK="0" diff --git a/tools/testing/selftests/firmware/fw_run_tests.sh b/tools/testing/selftests/firmware/fw_run_tests.sh index 777377078d5e..08a9bf043333 100755 --- a/tools/testing/selftests/firmware/fw_run_tests.sh +++ b/tools/testing/selftests/firmware/fw_run_tests.sh @@ -65,6 +65,8 @@ echo "Running namespace test: " $TEST_DIR/fw_namespace $DIR/trigger_request echo "OK" +$TEST_DIR/fw_builtin.sh + if [ -f $FW_FORCE_SYSFS_FALLBACK ]; then run_test_config_0001 run_test_config_0002