From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Guoyong Wang <guoyong.wang@mediatek.com>
Cc: Theodore Ts'o <tytso@mit.edu>, Tejun Heo <tj@kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com
Subject: Re: [PATCH] random: Fix the issue of '_might_sleep' function running in an atomic contex
Date: Wed, 20 Mar 2024 02:09:21 +0100 [thread overview]
Message-ID: <Zfo3QUFEy4wHkLEB@zx2c4.com> (raw)
In-Reply-To: <20240319093055.3252-1-guoyong.wang@mediatek.com>
On Tue, Mar 19, 2024 at 05:30:55PM +0800, Guoyong Wang wrote:
> On Mon, 18 Mar 2024 21:00:42 +0100, Jason A. Donenfeld wrote:
> > I'm wondering, though, rather than introducing a second function, maybe
> > execute_in_process_context() should just gain a `&& !in_atomic()`.
> > That'd make things a bit simpler.
>
> > However, I'm pretty sure in_atomic() isn't actually a reliable way of
> > determining that, depending on config. So maybe this should just call
> > the worker always (if system_wq isn't null).
>
> > Alternatively, any chance the call to add_input_randomness() could be
> > moved outside the spinlock, or does this not look possible?
>
> Hi Jason,
>
> Thanks for your suggestions.
>
> I am inclined to accept your second suggestion. My reluctance to accept
> the first is due to the concern that "&& !in_atomic()" could potentially
> alter the original meaning of the 'execute_in_process_context' interface.
> Regarding the third suggestion, modifying the logic associated with 'input'
> is not recommended.
Doesn't something like the below seem simplest? Just move the call out
of the spinlock and we're done.
diff --git a/drivers/input/input-core-private.h b/drivers/input/input-core-private.h
index 116834cf8868..717f239e28d0 100644
--- a/drivers/input/input-core-private.h
+++ b/drivers/input/input-core-private.h
@@ -10,7 +10,7 @@
struct input_dev;
void input_mt_release_slots(struct input_dev *dev);
-void input_handle_event(struct input_dev *dev,
+bool input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value);
#endif /* _INPUT_CORE_PRIVATE_H */
diff --git a/drivers/input/input.c b/drivers/input/input.c
index f71ea4fb173f..2faf46218c66 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -391,20 +391,22 @@ static void input_event_dispose(struct input_dev *dev, int disposition,
}
}
-void input_handle_event(struct input_dev *dev,
+bool input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
int disposition;
+ bool should_contribute_to_rng = false;
lockdep_assert_held(&dev->event_lock);
disposition = input_get_disposition(dev, type, code, &value);
if (disposition != INPUT_IGNORE_EVENT) {
if (type != EV_SYN)
- add_input_randomness(type, code, value);
+ should_contribute_to_rng = true;
input_event_dispose(dev, disposition, type, code, value);
}
+ return should_contribute_to_rng;
}
/**
@@ -428,12 +430,15 @@ void input_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
unsigned long flags;
+ bool should_contribute_to_rng;
if (is_event_supported(type, dev->evbit, EV_MAX)) {
spin_lock_irqsave(&dev->event_lock, flags);
- input_handle_event(dev, type, code, value);
+ should_contribute_to_rng = input_handle_event(dev, type, code, value);
spin_unlock_irqrestore(&dev->event_lock, flags);
+ if (should_contribute_to_rng)
+ add_input_randomness(type, code, value);
}
}
EXPORT_SYMBOL(input_event);
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-03-20 1:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-18 7:53 [PATCH] random: Fix the issue of '_might_sleep' function running in an atomic contex Guoyong Wang
2024-03-18 20:00 ` Jason A. Donenfeld
2024-03-19 9:30 ` Guoyong Wang
2024-03-20 1:09 ` Jason A. Donenfeld [this message]
2024-03-20 9:02 ` Guoyong Wang
2024-04-02 8:12 ` Guoyong Wang
2024-04-17 12:01 ` [PATCH] random: handle creditable entropy from atomic process context Jason A. Donenfeld
2024-04-19 8:41 ` [PATCH] random: Fix the issue of '_might_sleep' function running in an atomic contex Guoyong Wang
2024-04-19 8:55 ` Jason A. Donenfeld
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=Zfo3QUFEy4wHkLEB@zx2c4.com \
--to=jason@zx2c4.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=guoyong.wang@mediatek.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=tj@kernel.org \
--cc=tytso@mit.edu \
--cc=wsd_upstream@mediatek.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;
as well as URLs for NNTP newsgroup(s).