All of lore.kernel.org
 help / color / mirror / Atom feed
From: xiongxin <xiongxin@kylinos.cn>
To: tglx@linutronix.de, jikos@kernel.org, benjamin.tissoires@redhat.com
Cc: linux-input@vger.kernel.org, xiongxin <xiongxin@kylinos.cn>,
	stable@vger.kernel.org, Riwen Lu <luriwen@kylinos.cn>
Subject: [PATCH] irq: Resolve that mask_irq/unmask_irq may not be called in pairs
Date: Thu,  7 Dec 2023 09:40:03 +0800	[thread overview]
Message-ID: <20231207014003.12919-1-xiongxin@kylinos.cn> (raw)

When an interrupt controller uses a function such as handle_level_irq()
as an interrupt handler and the controller implements the irq_disable()
callback, the following scenario will appear in the i2c-hid driver in
the sleep scenario:

in the sleep flow, while the user is still triggering the i2c-hid
interrupt, we get the following function call:

  handle_level_irq()
    -> mask_ack_irq()
      -> mask_irq()
				i2c_hid_core_suspend()
				  -> disable_irq()
				    -> __irq_disable()
				      -> irq_state_set_disabled()
				      -> irq_state_set_masked()

  irq_thread_fn()
    -> irq_finalize_oneshot()
      -> if (!desc->threads_oneshot && !irqd_irq_disabled() &&
	     irqd_irq_masked())
      	 	unmask_threaded_irq()
		  -> unmask_irq()

That is, when __irq_disable() is called between mask_irq() and
irq_finalize_oneshot(), the code in irq_finalize_oneshot() will cause
the !irqd_irq_disabled() fails to enter the unmask_irq() branch, which
causes mask_irq/unmask_irq to be called unpaired and the i2c-hid
interrupt to be masked.

Since mask_irq/unmask_irq and irq_disabled() belong to two different
hardware registers or policies, the !irqd_irq_disabled() assertion may
not be used to determine whether unmask_irq() needs to be called.

Cc: stable@vger.kernel.org
Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Signed-off-by: Riwen Lu <luriwen@kylinos.cn>

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 1782f90cd8c6..9160fc9170b3 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1120,8 +1120,7 @@ static void irq_finalize_oneshot(struct irq_desc *desc,
 
 	desc->threads_oneshot &= ~action->thread_mask;
 
-	if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) &&
-	    irqd_irq_masked(&desc->irq_data))
+	if (!desc->threads_oneshot && irqd_irq_masked(&desc->irq_data))
 		unmask_threaded_irq(desc);
 
 out_unlock:
-- 
2.34.1


             reply	other threads:[~2023-12-07  1:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07  1:40 xiongxin [this message]
2023-12-08 13:52 ` [PATCH] irq: Resolve that mask_irq/unmask_irq may not be called in pairs Thomas Gleixner
2023-12-11  3:10   ` xiongxin
2023-12-12 15:17     ` Thomas Gleixner
2023-12-13  2:29       ` xiongxin
2023-12-13 14:59         ` Thomas Gleixner
2023-12-14  1:54           ` xiongxin
2023-12-14 10:06             ` Serge Semin
2023-12-14 16:11               ` Andy Shevchenko
2023-12-15  2:18                 ` xiongxin
2023-12-14 10:13             ` Thomas Gleixner
2023-12-12 16:57     ` Jiri Kosina
     [not found]     ` <1702429454313015.485.seg@mailgw>
2023-12-13  2:35       ` xiongxin
  -- strict thread matches above, loose matches on Subject: below --
2023-12-07  1:31 xiongxin

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=20231207014003.12919-1-xiongxin@kylinos.cn \
    --to=xiongxin@kylinos.cn \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=luriwen@kylinos.cn \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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.