From patchwork Fri Aug 16 00:09:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Branden X-Patchwork-Id: 11096635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7683356FF for ; Fri, 16 Aug 2019 00:10:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 670852891B for ; Fri, 16 Aug 2019 00:10:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AA56289AF; Fri, 16 Aug 2019 00:10:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D241A2891B for ; Fri, 16 Aug 2019 00:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfHPAJ5 (ORCPT ); Thu, 15 Aug 2019 20:09:57 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43879 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbfHPAJ5 (ORCPT ); Thu, 15 Aug 2019 20:09:57 -0400 Received: by mail-pg1-f194.google.com with SMTP id k3so2012100pgb.10 for ; Thu, 15 Aug 2019 17:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QdO+KVP1+sss46fGBNGuzASBMGiLUw4LDdShHVqVS8g=; b=SiGOxa4oChRUrJQDP/9WW9hEK3Q7GEDfzQioPwOA4DoanEr7H9XLhn3g4CCzTNjEbR QKg7ZhjgONqSMIffm8B2BmBOv+ICZjEv1O+9dICsOZiFfZgsi7r2pt9T/FS9S9tMq+Tf 4aOvx45ebDQyuYGew9Aw/jjLKO8/yufhC6IuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QdO+KVP1+sss46fGBNGuzASBMGiLUw4LDdShHVqVS8g=; b=SVNpL02f7f4hKRHzkPF4G2xxAnqq09mayPMF/hLBIpFdk2l49JYRjJQ4tmFw3gv4/U EFMO8caPloGqcf7izNIvBnJVQ7dZ00qc82t2ljXUQcS6C7/nMCo1OHoAYDbrBsBNjKLM ffxzSXOlSRfRcZkkaM96HwhAxQI+TZV2FGr9ZPqEJp8hOzy0SZBJk9hvmmgqPRSVpLR0 LHU0hDrZGrIH7bMvJFhNUrisPAnrK73Uh9HkywdmKXOn8L4/SLOet9mRkEPvOvoluZeN vN8heW2jXqTuy7/+VAl6zA43fbTG/p7cH8p81LtNB4qAgCXyObr2EyzGLh1mH9rPaJIj PtgA== X-Gm-Message-State: APjAAAWCVKpK++Er4dMTOHXYUVh0NVdlfNhIzfT3fDkqeORr8JlFAYwx DbysmCKibl48jNUJS/rk39fQNQ== X-Google-Smtp-Source: APXvYqybWBOdTqtForqqs5AXfctJmFJuGpFhCmJcKMASp2u0bNvd1fYKk9MUyCUmcumZ7pokMfTldg== X-Received: by 2002:aa7:97aa:: with SMTP id d10mr8052048pfq.176.1565914196045; Thu, 15 Aug 2019 17:09:56 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id g2sm4056916pfi.26.2019.08.15.17.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 17:09:55 -0700 (PDT) From: Scott Branden To: Luis Chamberlain , Greg Kroah-Hartman , Andy Gross , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org Cc: "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Kees Cook , Takashi Iwai , linux-kselftest@vger.kernel.org, Scott Branden Subject: [PATCH 1/3] test_firmware: add support for request_firmware_into_buf Date: Thu, 15 Aug 2019 17:09:43 -0700 Message-Id: <20190816000945.29810-2-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190816000945.29810-1-scott.branden@broadcom.com> References: <20190816000945.29810-1-scott.branden@broadcom.com> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add test config into_buf to allow request_firmware_into_buf to be called instead of request_firmware/request_firmware_direct. The number of parameters differ calling request_firmware_into_buf and support has not been added to test such api in test_firmware until now. Signed-off-by: Scott Branden Acked-by: Luis Chamberlain Acked-by: Shuah Khan --- lib/test_firmware.c | 50 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 6ca97a63b3d6..1aa430228ae6 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #define TEST_FIRMWARE_NAME "test-firmware.bin" #define TEST_FIRMWARE_NUM_REQS 4 +#define TEST_FIRMWARE_BUF_SIZE SZ_1K static DEFINE_MUTEX(test_fw_mutex); static const struct firmware *test_firmware; @@ -45,6 +47,8 @@ struct test_batched_req { * test_config - represents configuration for the test for different triggers * * @name: the name of the firmware file to look for + * @into_buf: when the into_buf is used if this is true + * request_firmware_into_buf() will be used instead. * @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 @@ -83,6 +87,7 @@ struct test_batched_req { */ struct test_config { char *name; + bool into_buf; bool sync_direct; bool send_uevent; u8 num_requests; @@ -176,6 +181,7 @@ static int __test_firmware_config_init(void) test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; test_fw_config->send_uevent = true; + test_fw_config->into_buf = false; test_fw_config->sync_direct = false; test_fw_config->req_firmware = request_firmware; test_fw_config->test_result = 0; @@ -244,6 +250,9 @@ static ssize_t config_show(struct device *dev, test_fw_config->send_uevent ? "FW_ACTION_HOTPLUG" : "FW_ACTION_NOHOTPLUG"); + len += scnprintf(buf+len, PAGE_SIZE - len, + "into_buf:\t\t%s\n", + test_fw_config->into_buf ? "true" : "false"); len += scnprintf(buf+len, PAGE_SIZE - len, "sync_direct:\t\t%s\n", test_fw_config->sync_direct ? "true" : "false"); @@ -393,6 +402,23 @@ static ssize_t config_num_requests_show(struct device *dev, } static DEVICE_ATTR_RW(config_num_requests); +static ssize_t config_into_buf_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + return test_dev_config_update_bool(buf, + count, + &test_fw_config->into_buf); +} + +static ssize_t config_into_buf_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return test_dev_config_show_bool(buf, test_fw_config->into_buf); +} +static DEVICE_ATTR_RW(config_into_buf); + static ssize_t config_sync_direct_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -522,7 +548,7 @@ static ssize_t trigger_async_request_store(struct device *dev, rc = count; } else { pr_err("failed to async load firmware\n"); - rc = -ENODEV; + rc = -ENOMEM; } out: @@ -585,7 +611,26 @@ static int test_fw_run_batch_request(void *data) return -EINVAL; } - req->rc = test_fw_config->req_firmware(&req->fw, req->name, req->dev); + if (test_fw_config->into_buf) { + void *test_buf; + + test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL); + if (!test_buf) + return -ENOSPC; + + req->rc = request_firmware_into_buf(&req->fw, + req->name, + req->dev, + test_buf, + TEST_FIRMWARE_BUF_SIZE); + if (!req->fw) + kfree(test_buf); + } else { + req->rc = test_fw_config->req_firmware(&req->fw, + req->name, + req->dev); + } + if (req->rc) { pr_info("#%u: batched sync load failed: %d\n", req->idx, req->rc); @@ -849,6 +894,7 @@ static struct attribute *test_dev_attrs[] = { TEST_FW_DEV_ATTR(config), TEST_FW_DEV_ATTR(config_name), TEST_FW_DEV_ATTR(config_num_requests), + TEST_FW_DEV_ATTR(config_into_buf), TEST_FW_DEV_ATTR(config_sync_direct), TEST_FW_DEV_ATTR(config_send_uevent), TEST_FW_DEV_ATTR(config_read_fw_idx), From patchwork Fri Aug 16 00:09:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Branden X-Patchwork-Id: 11096623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C5C013B1 for ; Fri, 16 Aug 2019 00:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BD2C2891B for ; Fri, 16 Aug 2019 00:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F26328986; Fri, 16 Aug 2019 00:10:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D26842891B for ; Fri, 16 Aug 2019 00:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726393AbfHPAKA (ORCPT ); Thu, 15 Aug 2019 20:10:00 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38896 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbfHPAJ7 (ORCPT ); Thu, 15 Aug 2019 20:09:59 -0400 Received: by mail-pg1-f194.google.com with SMTP id e11so2024666pga.5 for ; Thu, 15 Aug 2019 17:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L7zlafmTbJBNGW+lqh38oB6Up9ahjGRN/b/TjtVmaIo=; b=cQaZ0p7pFvsd9Hr18wDI8s193SCzyMkmWBf0bj8BCv35RjctLgCw3PFGqItI9joe+q vzn3J+aPF6prY3CNkTXelrkr3iVerzxk5Gsyr40/FqZZKpLxOuXDVH9Tl8hWzkp3wRT/ jI3FbiRpy9ZV4kBlN/hjOEgyayH/GtuoaxruE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L7zlafmTbJBNGW+lqh38oB6Up9ahjGRN/b/TjtVmaIo=; b=Eizd7dTuGoLuplQp3XcJfiaie8HXaX8dGjAa6Yz/MbmerYlkwsuAkmiWtBOadlRZTe 5eozEfwX/uWWk821Bos6AVRQ1JHfhL4d1Xu5CoptZ3hqR3AhtGxI3+jdL7U1ggnLtK0n yZs9TfRvcRSSgRV4T+t0qlWeF2RdJsF7qvvLAJy/yUH6ZyezClTKlfW8pjr4mtc0xQox wk+yDeKYFS0H6XR2+gjOpcdY51VI9pIL6amH7J7kpOtBnvYKApcXi5dm+L4PVoxSE5TI WVHvz4GjQCQYeoplq+402+LKMQb50W6OrZHasm0mD4g1EtmCRbEel2wCu7av4cWHv7+J /XRA== X-Gm-Message-State: APjAAAWo++FKjkIlpHF3pjcqAnZj91m6GSieG57VicI5RtFSm/82FCc4 1Fs4NglvUWvoJqNKCIYMf+drRQ== X-Google-Smtp-Source: APXvYqxX4LUFqRdF6+SYd0mMzhiMDnhqSixAQPO3XlYCqfi9W5hrtMv0HaYZaQ3AFS4jZ1Rh/5q9lA== X-Received: by 2002:a17:90a:ac02:: with SMTP id o2mr4609175pjq.134.1565914198446; Thu, 15 Aug 2019 17:09:58 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id g2sm4056916pfi.26.2019.08.15.17.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 17:09:58 -0700 (PDT) From: Scott Branden To: Luis Chamberlain , Greg Kroah-Hartman , Andy Gross , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org Cc: "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Kees Cook , Takashi Iwai , linux-kselftest@vger.kernel.org, Scott Branden Subject: [PATCH 2/3] selftest: firmware: Add request_firmware_into_buf tests Date: Thu, 15 Aug 2019 17:09:44 -0700 Message-Id: <20190816000945.29810-3-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190816000945.29810-1-scott.branden@broadcom.com> References: <20190816000945.29810-1-scott.branden@broadcom.com> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add tests cases for checking request_firmware_into_buf api. API was introduced into kernel with no testing present previously. Signed-off-by: Scott Branden Acked-by: Luis Chamberlain Acked-by: Shuah Khan --- .../selftests/firmware/fw_filesystem.sh | 57 ++++++++++++++++++- tools/testing/selftests/firmware/fw_lib.sh | 11 ++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh index f901076aa2ea..56894477c8bd 100755 --- a/tools/testing/selftests/firmware/fw_filesystem.sh +++ b/tools/testing/selftests/firmware/fw_filesystem.sh @@ -116,6 +116,16 @@ config_set_name() echo -n $1 > $DIR/config_name } +config_set_into_buf() +{ + echo 1 > $DIR/config_into_buf +} + +config_unset_into_buf() +{ + echo 0 > $DIR/config_into_buf +} + config_set_sync_direct() { echo 1 > $DIR/config_sync_direct @@ -153,11 +163,14 @@ config_set_read_fw_idx() read_firmwares() { - if [ "$1" = "xzonly" ]; then - fwfile="${FW}-orig" + if [ "$(cat $DIR/config_into_buf)" == "1" ]; then + fwfile="$FW_INTO_BUF" else fwfile="$FW" fi + if [ "$1" = "xzonly" ]; then + fwfile="${fwfile}-orig" + fi for i in $(seq 0 3); do config_set_read_fw_idx $i # Verify the contents are what we expect. @@ -194,6 +207,18 @@ test_batched_request_firmware_nofile() echo "OK" } +test_batched_request_firmware_into_buf_nofile() +{ + echo -n "Batched request_firmware_into_buf() nofile try #$1: " + config_reset + config_set_name nope-test-firmware.bin + config_set_into_buf + config_trigger_sync + read_firmwares_expect_nofile + release_all_firmware + echo "OK" +} + test_batched_request_firmware_direct_nofile() { echo -n "Batched request_firmware_direct() nofile try #$1: " @@ -259,6 +284,18 @@ test_batched_request_firmware() echo "OK" } +test_batched_request_firmware_into_buf() +{ + echo -n "Batched request_firmware_into_buf() $2 try #$1: " + config_reset + config_set_name $TEST_FIRMWARE_INTO_BUF_FILENAME + config_set_into_buf + config_trigger_sync + read_firmwares $2 + release_all_firmware + echo "OK" +} + test_batched_request_firmware_direct() { echo -n "Batched request_firmware_direct() $2 try #$1: " @@ -307,6 +344,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i normal done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i normal +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i normal done @@ -327,6 +368,10 @@ for i in $(seq 1 5); do test_batched_request_firmware_nofile $i done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf_nofile $i +done + for i in $(seq 1 5); do test_batched_request_firmware_direct_nofile $i done @@ -350,6 +395,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i both done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i both +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i both done @@ -370,6 +419,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i xzonly done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i xzonly +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i xzonly done diff --git a/tools/testing/selftests/firmware/fw_lib.sh b/tools/testing/selftests/firmware/fw_lib.sh index f236cc295450..b879305a766d 100755 --- a/tools/testing/selftests/firmware/fw_lib.sh +++ b/tools/testing/selftests/firmware/fw_lib.sh @@ -9,6 +9,12 @@ DIR=/sys/devices/virtual/misc/test_firmware PROC_CONFIG="/proc/config.gz" TEST_DIR=$(dirname $0) +# We need to load a different file to test request_firmware_into_buf +# I believe the issue is firmware loaded cached vs. non-cached +# with same filename is bungled. +# To reproduce rename this to test-firmware.bin +TEST_FIRMWARE_INTO_BUF_FILENAME=test-firmware-into-buf.bin + # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 @@ -108,6 +114,8 @@ setup_tmp_file() FWPATH=$(mktemp -d) FW="$FWPATH/test-firmware.bin" echo "ABCD0123" >"$FW" + FW_INTO_BUF="$FWPATH/$TEST_FIRMWARE_INTO_BUF_FILENAME" + echo "EFGH4567" >"$FW_INTO_BUF" NAME=$(basename "$FW") if [ "$TEST_REQS_FW_SET_CUSTOM_PATH" = "yes" ]; then echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path @@ -175,6 +183,9 @@ test_finish() if [ -f $FW ]; then rm -f "$FW" fi + if [ -f $FW_INTO_BUF ]; then + rm -f "$FW_INTO_BUF" + fi if [ -d $FWPATH ]; then rm -rf "$FWPATH" fi From patchwork Fri Aug 16 00:09:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Branden X-Patchwork-Id: 11096627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46B6B56FF for ; Fri, 16 Aug 2019 00:10:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386242891B for ; Fri, 16 Aug 2019 00:10:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2118928922; Fri, 16 Aug 2019 00:10:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B56F028922 for ; Fri, 16 Aug 2019 00:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbfHPAKC (ORCPT ); Thu, 15 Aug 2019 20:10:02 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38768 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfHPAKB (ORCPT ); Thu, 15 Aug 2019 20:10:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id o70so2157103pfg.5 for ; Thu, 15 Aug 2019 17:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XVcmO8RzpRC/BFyAhdGsg6GtacmmL8vW5DzIGcj2y00=; b=UyJlZup3Cv7yWgUuLvmQAnNfqDuhuM74GoMYvrExOhXCciNnhsHNjBZs2PEruaFfjG Jcui7w1fA8S36tDl5u6QHeKZF53YBkNnI8NRPTT9EsiCecxj3lysIb5IqKM09mKOGb1+ UDcxcyEFboiIxHynVYAC8K3EeVb9qsmZqVhaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XVcmO8RzpRC/BFyAhdGsg6GtacmmL8vW5DzIGcj2y00=; b=m7O7zIwYan3GD6pppy5LCvQGTsbxx3zCxkc5dNNXouJt2gnVLtI9yBcrx865t6JLlc hTv/kpZ437cRpWIchTbXE4J0xQMikvMPvi8M/5Sw/058h6Z/Ntdqft/b9Ogdj6R7NhFv 0MqtzSn9F4traJaoqytypQLKAq0IuLJ1ep+ewIq9luac/8aWK6mN7U+Ua05Y3g5FHpp+ bdpC5+Jb119R96Tmz7GTCW4i1rgg6r0pjX3mn/gPO0ZsEMfqAgWqEX9XYuk7g/amnn6a SWKQKcWd4E+G6znkAv4WqahnkKz6Hb+PnVN6k8cJ265bSNkbbMna2rAwoUswXJGRqgzZ LQ/g== X-Gm-Message-State: APjAAAUOSMFqVbH6cdZCFczYa0oXyJq50qTPcfOaKS+im+Xxyw8j1ZGV K4ookebAM7vzEgNFr5di3jmk4g== X-Google-Smtp-Source: APXvYqwAprqv8uGMD++iNatIdUckz9u8bL8pKGeHjyJM0EavcZ5h0ap9TeggfP0kBtQm1ZfTd3GqbQ== X-Received: by 2002:a17:90a:b947:: with SMTP id f7mr4557928pjw.63.1565914200957; Thu, 15 Aug 2019 17:10:00 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id g2sm4056916pfi.26.2019.08.15.17.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 17:10:00 -0700 (PDT) From: Scott Branden To: Luis Chamberlain , Greg Kroah-Hartman , Andy Gross , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org Cc: "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Kees Cook , Takashi Iwai , linux-kselftest@vger.kernel.org, Scott Branden Subject: [PATCH 3/3] firmware: add mutex fw_lock_fallback for race condition Date: Thu, 15 Aug 2019 17:09:45 -0700 Message-Id: <20190816000945.29810-4-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190816000945.29810-1-scott.branden@broadcom.com> References: <20190816000945.29810-1-scott.branden@broadcom.com> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A race condition exists between _request_firmware_prepare checking if firmware is assigned and firmware_fallback_sysfs creating a sysfs entry (kernel trace below). To avoid such condition add a mutex fw_lock_fallback to protect against such condition. misc test_firmware: Falling back to sysfs fallback for: nope-test-firmware.bin sysfs: cannot create duplicate filename '/devices/virtual/misc/test_firmware/nope-test-firmware.bin' CPU: 4 PID: 2059 Comm: test_firmware-3 Not tainted 5.3.0-rc4 #1 Hardware name: Dell Inc. OptiPlex 7010/0KRC95, BIOS A13 03/25/2013 Call Trace: dump_stack+0x67/0x90 sysfs_warn_dup.cold+0x17/0x24 sysfs_create_dir_ns+0xb3/0xd0 kobject_add_internal+0xa6/0x2a0 kobject_add+0x7e/0xb0 ? _cond_resched+0x15/0x30 device_add+0x121/0x670 firmware_fallback_sysfs+0x15c/0x3c9 _request_firmware+0x432/0x5a0 ? devres_find+0x63/0xc0 request_firmware_into_buf+0x63/0x80 test_fw_run_batch_request+0x96/0xe0 kthread+0xfb/0x130 ? reset_store+0x30/0x30 ? kthread_park+0x80/0x80 ret_from_fork+0x3a/0x50 kobject_add_internal failed for nope-test-firmware.bin with -EEXIST, don't try to register things with the same name in the same directory. Signed-off-by: Scott Branden --- drivers/base/firmware_loader/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index bf44c79beae9..ce9896e3b782 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -88,6 +88,7 @@ static inline struct fw_priv *to_fw_priv(struct kref *ref) /* fw_lock could be moved to 'struct fw_sysfs' but since it is just * guarding for corner cases a global lock should be OK */ DEFINE_MUTEX(fw_lock); +DEFINE_MUTEX(fw_lock_fallback); static struct firmware_cache fw_cache; @@ -758,6 +759,17 @@ _request_firmware(const struct firmware **firmware_p, const char *name, if (!firmware_p) return -EINVAL; + /* + * There is a race condition between _request_firmware_prepare checking + * if firmware is assigned and firmware_fallback_sysfs creating sysfs + * entries with duplicate names. + * Yet, with this lock the firmware_test locks up with cache enabled + * and no event used during firmware test. + * This points to some very racy code I don't know how to entirely fix. + */ + if (opt_flags & FW_OPT_NOCACHE) + mutex_lock(&fw_lock_fallback); + if (!name || name[0] == '\0') { ret = -EINVAL; goto out; @@ -791,6 +803,9 @@ _request_firmware(const struct firmware **firmware_p, const char *name, fw = NULL; } + if (opt_flags & FW_OPT_NOCACHE) + mutex_unlock(&fw_lock_fallback); + *firmware_p = fw; return ret; }