All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: gregkh@linuxfoundation.org
Cc: jakub.kicinski@netronome.com, nbroeking@me.com,
	ming.lei@redhat.com, mfuzzey@parkeon.com, ebiederm@xmission.com,
	dmitry.torokhov@gmail.com, wagi@monom.org, dwmw2@infradead.org,
	jewalt@lgsinnovations.com, rafal@milecki.pl,
	arend.vanspriel@broadcom.com, rjw@rjwysocki.net,
	yi1.li@linux.intel.com, atull@kernel.org,
	moritz.fischer@ettus.com, pmladek@suse.com,
	johannes.berg@intel.com, emmanuel.grumbach@intel.com,
	luciano.coelho@intel.com, kvalo@codeaurora.org, luto@kernel.org,
	torvalds@linux-foundation.org, keescook@chromium.org,
	takahiro.akashi@linaro.org, dhowells@redhat.com,
	pjones@redhat.com, hdegoede@redhat.com, alan@linux.intel.com,
	tytso@mit.edu, paul.gortmaker@windriver.com, mtosatti@redhat.com,
	mawilcox@microsoft.com, linux-kernel@vger.kernel.org,
	"[4.10+]" <stable@vger.kernel.org>,
	"Luis R . Rodriguez" <mcgrof@kernel.org>
Subject: [PATCH v2] firmware: fix batched requests - wake all waiters
Date: Mon, 26 Jun 2017 14:23:12 -0700	[thread overview]
Message-ID: <20170626212312.31958-1-mcgrof@kernel.org> (raw)
In-Reply-To: <20170626212036.GE21846@wotan.suse.de>

From: Jakub Kicinski <jakub.kicinski@netronome.com>

The firmware cache mechanism serves two purposes, the secondary purpose is
not well documented nor understood. This fixes a regression with the secondary
purpose of the firmware cache mechanism: batched requests.

The firmware cache is used for:

1) Addressing races with file lookups during the suspend/resume cycle
   by keeping firmware in memory during the cycle

2) Batched requests for the same file rely only on work from the first file
   lookup, which keeps the firmware in memory until the last release_firmware()
   is called

Batched requests *only* take effect if secondary requests come in prior to the
first user calling release_firmware(). The devres name used for the internal
firmware cache is used as a hint other pending requests are ongoing, the
firmware buffer data is kept in memory until the last user of the buffer
calls release_firmware(), therefore serializing requests and delaying the
release until all requests are done.

Batched requests wait for a wakup or signal (we only accept SIGKILL now) so we
can rely on the first file fetch to write to the pending secondary requests.
Commit 5b029624948d ("firmware: do not use fw_lock for fw_state protection")
ported the firmware API to use swait, and in doing so failed to convert
complete_all() to swake_up_all() -- it used swake_up(), loosing the ability
for *some* batched requests to take effect.

Without this fix it has been reported plugging in two Intel 6260 Wifi cards
on a system will end up enumerating the two devices only 50% of the time
[0]. The ported swake_up() should have actually two devices, however,
*if more than two cards are used* the swake_up() would not suffice. This
change is only part of the required fixes for batched requests. Subsequent
fixes will follow.

This particular change should fix the cases where more than three requests
with the same firmware name is used, otherwise batched requests will wait for
MAX_SCHEDULE_TIMEOUT and just timeout eventually.

[0] https://bugzilla.kernel.org/show_bug.cgi?id=195477

Fixes: 5b029624948d ("firmware: do not use fw_lock for fw_state protection")
CC: <stable@vger.kernel.org>    [4.10+]
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
[mcgrof: expanded on impact on commit log]
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---

Greg, I think it would make sense to queue this in after the signal stable
fixes [1].

[1] https://lkml.kernel.org/r/20170614222017.14653-1-mcgrof@kernel.org

 drivers/base/firmware_class.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b9f907eedbf7..686381a621a0 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -148,7 +148,7 @@ static void __fw_state_set(struct fw_state *fw_st,
 	WRITE_ONCE(fw_st->status, status);
 
 	if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED)
-		swake_up(&fw_st->wq);
+		swake_up_all(&fw_st->wq);
 }
 
 #define fw_state_start(fw_st)					\
-- 
2.11.0

  reply	other threads:[~2017-06-26 21:23 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 23:37 [PATCH] firmware: wake all waiters Jakub Kicinski
2017-06-26 21:20 ` Luis R. Rodriguez
2017-06-26 21:23   ` Luis R. Rodriguez [this message]
2017-06-29 15:16     ` [PATCH v2] firmware: fix batched requests - " Greg KH
2017-06-29 15:17       ` Greg KH
2017-06-29 17:36         ` Luis R. Rodriguez
2017-06-26 23:41   ` [PATCH] firmware: " Luis R. Rodriguez
2017-06-27  2:10   ` Jakub Kicinski
2017-06-27 16:39     ` Luis R. Rodriguez
2017-06-27 21:25       ` Jakub Kicinski
2017-06-27 22:24         ` Luis R. Rodriguez
2017-06-27 22:39           ` Jakub Kicinski
2017-06-27 23:50             ` Luis R. Rodriguez
2017-06-28  7:06           ` [systemd-devel] " Lennart Poettering
2017-06-28 16:06             ` Luis R. Rodriguez
2017-06-28 16:21               ` Lennart Poettering
2017-06-28 17:57                 ` Luis R. Rodriguez
2017-06-29 19:56               ` Daniel Wagner
2017-06-27 17:48     ` Bjorn Andersson
2017-06-27 18:03       ` Luis R. Rodriguez
2017-06-27 18:59         ` Bjorn Andersson
2017-06-27 19:08           ` Luis R. Rodriguez
2017-06-27 19:52             ` Bjorn Andersson
2017-06-27 20:24               ` Luis R. Rodriguez
2017-06-26 21:44 ` Linus Torvalds
2017-06-26 23:30   ` Luis R. Rodriguez
2017-06-26 23:43     ` Linus Torvalds
2017-06-27  0:15       ` Luis R. Rodriguez
2017-06-28 13:45         ` Davidlohr Bueso
2017-06-28 15:58           ` Luis R. Rodriguez
2017-06-28 19:03             ` Davidlohr Bueso
2017-06-29 19:08         ` Davidlohr Bueso
2017-06-29 19:48           ` Luis R. Rodriguez
2017-06-30 16:32             ` Davidlohr Bueso
2017-07-05 16:18     ` Peter Zijlstra
2017-07-05 16:33       ` Linus Torvalds
2017-07-12 18:45         ` Luis R. Rodriguez

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=20170626212312.31958-1-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=alan@linux.intel.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=atull@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=ebiederm@xmission.com \
    --cc=emmanuel.grumbach@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jewalt@lgsinnovations.com \
    --cc=johannes.berg@intel.com \
    --cc=keescook@chromium.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    --cc=luto@kernel.org \
    --cc=mawilcox@microsoft.com \
    --cc=mfuzzey@parkeon.com \
    --cc=ming.lei@redhat.com \
    --cc=moritz.fischer@ettus.com \
    --cc=mtosatti@redhat.com \
    --cc=nbroeking@me.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=pjones@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rafal@milecki.pl \
    --cc=rjw@rjwysocki.net \
    --cc=stable@vger.kernel.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=wagi@monom.org \
    --cc=yi1.li@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.