From: Luis Chamberlain <mcgrof@kernel.org>
To: Junyong Sun <sunjy516@gmail.com>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
linux-kernel@vger.kernel.org, sunjunyong@xiaomi.com
Subject: Re: [PATCH v2] firmware: fix a double abort case with fw_load_sysfs_fallback
Date: Tue, 3 Mar 2020 15:05:54 +0000 [thread overview]
Message-ID: <20200303150554.GI11244@42.do-not-panic.com> (raw)
In-Reply-To: <1583202968-28792-1-git-send-email-sunjunyong@xiaomi.com>
On Tue, Mar 03, 2020 at 10:36:08AM +0800, Junyong Sun wrote:
> fw_sysfs_wait_timeout may return err with -ENOENT
> at fw_load_sysfs_fallback and firmware is already
> in abort status, no need to abort again, so skip it.
>
> This issue is caused by concurrent situation like below:
> when thread 1# wait firmware loading, thread 2# may write
> -1 to abort loading and wakeup thread 1# before it timeout.
> so wait_for_completion_killable_timeout of thread 1# would
> return remaining time which is != 0 with fw_st->status
> FW_STATUS_ABORTED.And the results would be converted into
> err -ENOENT in __fw_state_wait_common and transfered to
> fw_load_sysfs_fallback in thread 1#.
> The -ENOENT means firmware status is already at ABORTED,
> so fw_load_sysfs_fallback no need to get mutex to abort again.
> -----------------------------
> thread 1#,wait for loading
> fw_load_sysfs_fallback
> ->fw_sysfs_wait_timeout
> ->__fw_state_wait_common
> ->wait_for_completion_killable_timeout
>
> in __fw_state_wait_common,
> ...
> 93 ret = wait_for_completion_killable_timeout(&fw_st->completion, timeout);
> 94 if (ret != 0 && fw_st->status == FW_STATUS_ABORTED)
> 95 return -ENOENT;
> 96 if (!ret)
> 97 return -ETIMEDOUT;
> 98
> 99 return ret < 0 ? ret : 0;
> -----------------------------
> thread 2#, write -1 to abort loading
> firmware_loading_store
> ->fw_load_abort
> ->__fw_load_abort
> ->fw_state_aborted
> ->__fw_state_set
> ->complete_all
>
> in __fw_state_set,
> ...
> 111 if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED)
> 112 complete_all(&fw_st->completion);
> -------------------------------------------
> BTW,the double abort issue would not cause kernel panic or create an issue,
> but slow down it sometimes.The change is just a minor optimization.
>
> Signed-off-by: Junyong Sun <sunjunyong@xiaomi.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
prev parent reply other threads:[~2020-03-03 15:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 2:36 [PATCH v2] firmware: fix a double abort case with fw_load_sysfs_fallback Junyong Sun
2020-03-03 15:05 ` Luis Chamberlain [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200303150554.GI11244@42.do-not-panic.com \
--to=mcgrof@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sunjunyong@xiaomi.com \
--cc=sunjy516@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox