linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers
@ 2024-04-22 15:36 Sergei Antonov
  2024-04-22 17:56 ` Linus Walleij
  2024-04-25 16:22 ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Sergei Antonov @ 2024-04-22 15:36 UTC (permalink / raw)
  To: linux-mmc, linux-block; +Cc: linus.walleij, Sergei Antonov

When e.g. 8 bytes are to be read, sgm->consumed equals 8 immediately after
sg_miter_next() call. The driver then increments it as bytes are read,
so sgm->consumed becomes 16 and this warning triggers in sg_miter_stop():
WARN_ON(miter->consumed > miter->length);

WARNING: CPU: 0 PID: 28 at lib/scatterlist.c:925 sg_miter_stop+0x2c/0x10c
CPU: 0 PID: 28 Comm: kworker/0:2 Tainted: G        W          6.9.0-rc5-dirty #249
Hardware name: Generic DT based system
Workqueue: events_freezable mmc_rescan
Call trace:.
 unwind_backtrace from show_stack+0x10/0x14
 show_stack from dump_stack_lvl+0x44/0x5c
 dump_stack_lvl from __warn+0x78/0x16c
 __warn from warn_slowpath_fmt+0xb0/0x160
 warn_slowpath_fmt from sg_miter_stop+0x2c/0x10c
 sg_miter_stop from moxart_request+0xb0/0x468
 moxart_request from mmc_start_request+0x94/0xa8
 mmc_start_request from mmc_wait_for_req+0x60/0xa8
 mmc_wait_for_req from mmc_app_send_scr+0xf8/0x150
 mmc_app_send_scr from mmc_sd_setup_card+0x1c/0x420
 mmc_sd_setup_card from mmc_sd_init_card+0x12c/0x4dc
 mmc_sd_init_card from mmc_attach_sd+0xf0/0x16c
 mmc_attach_sd from mmc_rescan+0x1e0/0x298
 mmc_rescan from process_scheduled_works+0x2e4/0x4ec
 process_scheduled_works from worker_thread+0x1ec/0x24c
 worker_thread from kthread+0xd4/0xe0
 kthread from ret_from_fork+0x14/0x38

This patch adds initial zeroing of sgm->consumed. It is then incremented
as bytes are read or written.

Signed-off-by: Sergei Antonov <saproj@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Fixes: 3ee0e7c3e67c ("mmc: moxart-mmc: Use sg_miter for PIO")
---
 drivers/mmc/host/moxart-mmc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
index b88d6dec209f..9a5f75163aca 100644
--- a/drivers/mmc/host/moxart-mmc.c
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -300,6 +300,7 @@ static void moxart_transfer_pio(struct moxart_host *host)
 	remain = sgm->length;
 	if (remain > host->data_len)
 		remain = host->data_len;
+	sgm->consumed = 0;
 
 	if (data->flags & MMC_DATA_WRITE) {
 		while (remain > 0) {
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers
  2024-04-22 15:36 [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers Sergei Antonov
@ 2024-04-22 17:56 ` Linus Walleij
  2024-04-23 10:11   ` Sergei Antonov
  2024-04-25 16:22 ` Ulf Hansson
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2024-04-22 17:56 UTC (permalink / raw)
  To: Sergei Antonov; +Cc: linux-mmc, linux-block

On Mon, Apr 22, 2024 at 5:36 PM Sergei Antonov <saproj@gmail.com> wrote:

> When e.g. 8 bytes are to be read, sgm->consumed equals 8 immediately after
> sg_miter_next() call. The driver then increments it as bytes are read,
> so sgm->consumed becomes 16 and this warning triggers in sg_miter_stop():
> WARN_ON(miter->consumed > miter->length);
>
> WARNING: CPU: 0 PID: 28 at lib/scatterlist.c:925 sg_miter_stop+0x2c/0x10c
> CPU: 0 PID: 28 Comm: kworker/0:2 Tainted: G        W          6.9.0-rc5-dirty #249
> Hardware name: Generic DT based system
> Workqueue: events_freezable mmc_rescan
> Call trace:.
>  unwind_backtrace from show_stack+0x10/0x14
>  show_stack from dump_stack_lvl+0x44/0x5c
>  dump_stack_lvl from __warn+0x78/0x16c
>  __warn from warn_slowpath_fmt+0xb0/0x160
>  warn_slowpath_fmt from sg_miter_stop+0x2c/0x10c
>  sg_miter_stop from moxart_request+0xb0/0x468
>  moxart_request from mmc_start_request+0x94/0xa8
>  mmc_start_request from mmc_wait_for_req+0x60/0xa8
>  mmc_wait_for_req from mmc_app_send_scr+0xf8/0x150
>  mmc_app_send_scr from mmc_sd_setup_card+0x1c/0x420
>  mmc_sd_setup_card from mmc_sd_init_card+0x12c/0x4dc
>  mmc_sd_init_card from mmc_attach_sd+0xf0/0x16c
>  mmc_attach_sd from mmc_rescan+0x1e0/0x298
>  mmc_rescan from process_scheduled_works+0x2e4/0x4ec
>  process_scheduled_works from worker_thread+0x1ec/0x24c
>  worker_thread from kthread+0xd4/0xe0
>  kthread from ret_from_fork+0x14/0x38
>
> This patch adds initial zeroing of sgm->consumed. It is then incremented
> as bytes are read or written.
>
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Fixes: 3ee0e7c3e67c ("mmc: moxart-mmc: Use sg_miter for PIO")

Oh it was that simple.

Thanks for fixing this Sergei!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers
  2024-04-22 17:56 ` Linus Walleij
@ 2024-04-23 10:11   ` Sergei Antonov
  0 siblings, 0 replies; 4+ messages in thread
From: Sergei Antonov @ 2024-04-23 10:11 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-mmc, linux-block

On Mon, 22 Apr 2024 at 20:56, Linus Walleij <linus.walleij@linaro.org> wrote:

> Oh it was that simple.
>
> Thanks for fixing this Sergei!
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

To fix this WARN_ON was indeed simple. But the "BUG: scheduling while
atomic" problem I reported in the other thread is a separate problem.
So I'll respond there.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers
  2024-04-22 15:36 [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers Sergei Antonov
  2024-04-22 17:56 ` Linus Walleij
@ 2024-04-25 16:22 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2024-04-25 16:22 UTC (permalink / raw)
  To: Sergei Antonov; +Cc: linux-mmc, linux-block, linus.walleij

On Mon, 22 Apr 2024 at 17:36, Sergei Antonov <saproj@gmail.com> wrote:
>
> When e.g. 8 bytes are to be read, sgm->consumed equals 8 immediately after
> sg_miter_next() call. The driver then increments it as bytes are read,
> so sgm->consumed becomes 16 and this warning triggers in sg_miter_stop():
> WARN_ON(miter->consumed > miter->length);
>
> WARNING: CPU: 0 PID: 28 at lib/scatterlist.c:925 sg_miter_stop+0x2c/0x10c
> CPU: 0 PID: 28 Comm: kworker/0:2 Tainted: G        W          6.9.0-rc5-dirty #249
> Hardware name: Generic DT based system
> Workqueue: events_freezable mmc_rescan
> Call trace:.
>  unwind_backtrace from show_stack+0x10/0x14
>  show_stack from dump_stack_lvl+0x44/0x5c
>  dump_stack_lvl from __warn+0x78/0x16c
>  __warn from warn_slowpath_fmt+0xb0/0x160
>  warn_slowpath_fmt from sg_miter_stop+0x2c/0x10c
>  sg_miter_stop from moxart_request+0xb0/0x468
>  moxart_request from mmc_start_request+0x94/0xa8
>  mmc_start_request from mmc_wait_for_req+0x60/0xa8
>  mmc_wait_for_req from mmc_app_send_scr+0xf8/0x150
>  mmc_app_send_scr from mmc_sd_setup_card+0x1c/0x420
>  mmc_sd_setup_card from mmc_sd_init_card+0x12c/0x4dc
>  mmc_sd_init_card from mmc_attach_sd+0xf0/0x16c
>  mmc_attach_sd from mmc_rescan+0x1e0/0x298
>  mmc_rescan from process_scheduled_works+0x2e4/0x4ec
>  process_scheduled_works from worker_thread+0x1ec/0x24c
>  worker_thread from kthread+0xd4/0xe0
>  kthread from ret_from_fork+0x14/0x38
>
> This patch adds initial zeroing of sgm->consumed. It is then incremented
> as bytes are read or written.
>
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Fixes: 3ee0e7c3e67c ("mmc: moxart-mmc: Use sg_miter for PIO")

Applied for fixes, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/moxart-mmc.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
> index b88d6dec209f..9a5f75163aca 100644
> --- a/drivers/mmc/host/moxart-mmc.c
> +++ b/drivers/mmc/host/moxart-mmc.c
> @@ -300,6 +300,7 @@ static void moxart_transfer_pio(struct moxart_host *host)
>         remain = sgm->length;
>         if (remain > host->data_len)
>                 remain = host->data_len;
> +       sgm->consumed = 0;
>
>         if (data->flags & MMC_DATA_WRITE) {
>                 while (remain > 0) {
> --
> 2.40.1
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-25 16:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 15:36 [PATCH] mmc: moxart: fix handling of sgm->consumed, otherwise WARN_ON triggers Sergei Antonov
2024-04-22 17:56 ` Linus Walleij
2024-04-23 10:11   ` Sergei Antonov
2024-04-25 16:22 ` Ulf Hansson

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).