All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-10-05 11:55 Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2023-10-05 11:55 UTC (permalink / raw)
  To: milkfafa; +Cc: linux-media

Hello Marvin Lin,

The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
the following Smatch static checker warning:

	drivers/media/platform/nuvoton/npcm-video.c:493 npcm_video_find_rect()
	warn: sleeping in atomic context

drivers/media/platform/nuvoton/npcm-video.c
    488 static int npcm_video_find_rect(struct npcm_video *video,
    489                                 struct rect_list_info *info,
    490                                 unsigned int offset)
    491 {
    492         if (offset < info->tile_perline) {
--> 493                 info->list = npcm_video_new_rect(video, offset, info->index);

Does a sleeping allocation.

    494                 if (!info->list) {
    495                         dev_err(video->dev, "Failed to allocate rect_list\n");
    496                         return -ENOMEM;
    497                 }
    498 
    499                 npcm_video_merge_rect(video, info);
    500         }
    501         return 0;
    502 }

The problematic call tree is:

npcm_video_irq() <- disables preempt
-> npcm_video_hextile()
   -> npcm_video_get_diff_rect()
      -> npcm_video_get_rect_list()
         -> npcm_video_build_table()
            -> npcm_video_find_rect()

The npcm_video_irq() function holds spin_lock(&video->lock) and we can't
sleep while holding a spinlock.

regards,
dan carpenter

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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
  2023-09-27  8:36     ` Dan Carpenter
@ 2023-09-27 12:09       ` Kun-Fa Lin
  -1 siblings, 0 replies; 9+ messages in thread
From: Kun-Fa Lin @ 2023-09-27 12:09 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Hans Verkuil, linux-media, openbmc

Hi Dan,

> > On 26/09/2023 16:23, Dan Carpenter wrote:
> > > Hello Marvin Lin,
> > >
> > > The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> > > capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> > > the following Smatch static checker warning:
> > >
> > >     drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> > >     warn: sleeping in atomic context
> >
> > Hmm, why didn't my smatch run see this? Does this check require something
> > special? Does it rely on having run build_kernel_data.sh?
>
> Yep.  It relies on build_kernel_data.sh.  Otherwise it that code is all
> released.

I can see these warnings after running build_kernel_data.sh:
drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
warn: sleeping in atomic context
drivers/media/platform/nuvoton/npcm-video.c:1089 npcm_video_irq()
warn: sleeping in atomic context

I'll send below patch to fix them, thanks for the bug report.

--- a/drivers/media/platform/nuvoton/npcm-video.c
+++ b/drivers/media/platform/nuvoton/npcm-video.c
@@ -412,7 +412,7 @@ static unsigned int npcm_video_add_rect(struct
npcm_video *video,
        struct rect_list *list = NULL;
        struct v4l2_rect *r;

-       list = kzalloc(sizeof(*list), GFP_KERNEL);
+       list = kzalloc(sizeof(*list), GFP_ATOMIC);
        if (!list)
                return 0;

@@ -467,7 +467,7 @@ static struct rect_list
*npcm_video_new_rect(struct npcm_video *video,
        struct rect_list *list = NULL;
        struct v4l2_rect *r;

-       list = kzalloc(sizeof(*list), GFP_KERNEL);
+       list = kzalloc(sizeof(*list), GFP_ATOMIC);
        if (!list)
                return NULL;

Regards,
Marvin

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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-09-27 12:09       ` Kun-Fa Lin
  0 siblings, 0 replies; 9+ messages in thread
From: Kun-Fa Lin @ 2023-09-27 12:09 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Hans Verkuil, openbmc, linux-media

Hi Dan,

> > On 26/09/2023 16:23, Dan Carpenter wrote:
> > > Hello Marvin Lin,
> > >
> > > The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> > > capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> > > the following Smatch static checker warning:
> > >
> > >     drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> > >     warn: sleeping in atomic context
> >
> > Hmm, why didn't my smatch run see this? Does this check require something
> > special? Does it rely on having run build_kernel_data.sh?
>
> Yep.  It relies on build_kernel_data.sh.  Otherwise it that code is all
> released.

I can see these warnings after running build_kernel_data.sh:
drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
warn: sleeping in atomic context
drivers/media/platform/nuvoton/npcm-video.c:1089 npcm_video_irq()
warn: sleeping in atomic context

I'll send below patch to fix them, thanks for the bug report.

--- a/drivers/media/platform/nuvoton/npcm-video.c
+++ b/drivers/media/platform/nuvoton/npcm-video.c
@@ -412,7 +412,7 @@ static unsigned int npcm_video_add_rect(struct
npcm_video *video,
        struct rect_list *list = NULL;
        struct v4l2_rect *r;

-       list = kzalloc(sizeof(*list), GFP_KERNEL);
+       list = kzalloc(sizeof(*list), GFP_ATOMIC);
        if (!list)
                return 0;

@@ -467,7 +467,7 @@ static struct rect_list
*npcm_video_new_rect(struct npcm_video *video,
        struct rect_list *list = NULL;
        struct v4l2_rect *r;

-       list = kzalloc(sizeof(*list), GFP_KERNEL);
+       list = kzalloc(sizeof(*list), GFP_ATOMIC);
        if (!list)
                return NULL;

Regards,
Marvin

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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
  2023-09-27  8:04   ` Hans Verkuil
@ 2023-09-27  8:36     ` Dan Carpenter
  -1 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2023-09-27  8:36 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: milkfafa, linux-media, openbmc

On Wed, Sep 27, 2023 at 10:04:01AM +0200, Hans Verkuil wrote:
> Hi Dan,
> 
> On 26/09/2023 16:23, Dan Carpenter wrote:
> > Hello Marvin Lin,
> > 
> > The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> > capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> > the following Smatch static checker warning:
> > 
> > 	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> > 	warn: sleeping in atomic context
> 
> Hmm, why didn't my smatch run see this? Does this check require something
> special? Does it rely on having run build_kernel_data.sh?

Yep.  It relies on build_kernel_data.sh.  Otherwise it that code is all
released.

regards,
dan carpenter


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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-09-27  8:36     ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2023-09-27  8:36 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: openbmc, milkfafa, linux-media

On Wed, Sep 27, 2023 at 10:04:01AM +0200, Hans Verkuil wrote:
> Hi Dan,
> 
> On 26/09/2023 16:23, Dan Carpenter wrote:
> > Hello Marvin Lin,
> > 
> > The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> > capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> > the following Smatch static checker warning:
> > 
> > 	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> > 	warn: sleeping in atomic context
> 
> Hmm, why didn't my smatch run see this? Does this check require something
> special? Does it rely on having run build_kernel_data.sh?

Yep.  It relies on build_kernel_data.sh.  Otherwise it that code is all
released.

regards,
dan carpenter


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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
  2023-09-26 14:23 ` Dan Carpenter
@ 2023-09-27  8:04   ` Hans Verkuil
  -1 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2023-09-27  8:04 UTC (permalink / raw)
  To: Dan Carpenter, milkfafa; +Cc: linux-media, openbmc

Hi Dan,

On 26/09/2023 16:23, Dan Carpenter wrote:
> Hello Marvin Lin,
> 
> The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> the following Smatch static checker warning:
> 
> 	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> 	warn: sleeping in atomic context

Hmm, why didn't my smatch run see this? Does this check require something
special? Does it rely on having run build_kernel_data.sh?

Regards,

	Hans

> 
> drivers/media/platform/nuvoton/npcm-video.c
>     998 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr)
>     999 {
>     1000         unsigned int width = video->active_timings.width;
>     1001         unsigned int height = video->active_timings.height;
>     1002         unsigned int i, len, offset, bytes = 0;
>     1003 
> --> 1004         video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height);
>                                       ^^^^^^^^^^^^^^^^^^^
> This function does a sleeping allocation (GFP_KERNEL).  However
> npcm_video_irq() is holding spin_lock(&video->lock); so this is a
> sleeping in atomic bug.
> 
>     1005 
>     1006         for (i = 0; i < height; i++) {
>     1007                 len = width * video->bytesperpixel;
>     1008                 offset = i * video->bytesperline;
>     1009 
>     1010                 memcpy(addr + bytes, video->src.virt + offset, len);
>     1011                 bytes += len;
>     1012         }
>     1013 
>     1014         return bytes;
>     1015 }
> 
> regards,
> dan carpenter


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

* Re: [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-09-27  8:04   ` Hans Verkuil
  0 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2023-09-27  8:04 UTC (permalink / raw)
  To: Dan Carpenter, milkfafa; +Cc: openbmc, linux-media

Hi Dan,

On 26/09/2023 16:23, Dan Carpenter wrote:
> Hello Marvin Lin,
> 
> The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
> capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
> the following Smatch static checker warning:
> 
> 	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
> 	warn: sleeping in atomic context

Hmm, why didn't my smatch run see this? Does this check require something
special? Does it rely on having run build_kernel_data.sh?

Regards,

	Hans

> 
> drivers/media/platform/nuvoton/npcm-video.c
>     998 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr)
>     999 {
>     1000         unsigned int width = video->active_timings.width;
>     1001         unsigned int height = video->active_timings.height;
>     1002         unsigned int i, len, offset, bytes = 0;
>     1003 
> --> 1004         video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height);
>                                       ^^^^^^^^^^^^^^^^^^^
> This function does a sleeping allocation (GFP_KERNEL).  However
> npcm_video_irq() is holding spin_lock(&video->lock); so this is a
> sleeping in atomic bug.
> 
>     1005 
>     1006         for (i = 0; i < height; i++) {
>     1007                 len = width * video->bytesperpixel;
>     1008                 offset = i * video->bytesperline;
>     1009 
>     1010                 memcpy(addr + bytes, video->src.virt + offset, len);
>     1011                 bytes += len;
>     1012         }
>     1013 
>     1014         return bytes;
>     1015 }
> 
> regards,
> dan carpenter


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

* [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-09-26 14:23 ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2023-09-26 14:23 UTC (permalink / raw)
  To: milkfafa; +Cc: linux-media, openbmc

Hello Marvin Lin,

The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
the following Smatch static checker warning:

	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
	warn: sleeping in atomic context

drivers/media/platform/nuvoton/npcm-video.c
    998 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr)
    999 {
    1000         unsigned int width = video->active_timings.width;
    1001         unsigned int height = video->active_timings.height;
    1002         unsigned int i, len, offset, bytes = 0;
    1003 
--> 1004         video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height);
                                      ^^^^^^^^^^^^^^^^^^^
This function does a sleeping allocation (GFP_KERNEL).  However
npcm_video_irq() is holding spin_lock(&video->lock); so this is a
sleeping in atomic bug.

    1005 
    1006         for (i = 0; i < height; i++) {
    1007                 len = width * video->bytesperpixel;
    1008                 offset = i * video->bytesperline;
    1009 
    1010                 memcpy(addr + bytes, video->src.virt + offset, len);
    1011                 bytes += len;
    1012         }
    1013 
    1014         return bytes;
    1015 }

regards,
dan carpenter

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

* [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine
@ 2023-09-26 14:23 ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2023-09-26 14:23 UTC (permalink / raw)
  To: milkfafa; +Cc: openbmc, linux-media

Hello Marvin Lin,

The patch 70721089985c: "media: nuvoton: Add driver for NPCM video
capture and encoding engine" from Sep 22, 2023 (linux-next), leads to
the following Smatch static checker warning:

	drivers/media/platform/nuvoton/npcm-video.c:1004 npcm_video_raw()
	warn: sleeping in atomic context

drivers/media/platform/nuvoton/npcm-video.c
    998 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr)
    999 {
    1000         unsigned int width = video->active_timings.width;
    1001         unsigned int height = video->active_timings.height;
    1002         unsigned int i, len, offset, bytes = 0;
    1003 
--> 1004         video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height);
                                      ^^^^^^^^^^^^^^^^^^^
This function does a sleeping allocation (GFP_KERNEL).  However
npcm_video_irq() is holding spin_lock(&video->lock); so this is a
sleeping in atomic bug.

    1005 
    1006         for (i = 0; i < height; i++) {
    1007                 len = width * video->bytesperpixel;
    1008                 offset = i * video->bytesperline;
    1009 
    1010                 memcpy(addr + bytes, video->src.virt + offset, len);
    1011                 bytes += len;
    1012         }
    1013 
    1014         return bytes;
    1015 }

regards,
dan carpenter

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

end of thread, other threads:[~2023-10-05 14:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-05 11:55 [bug report] media: nuvoton: Add driver for NPCM video capture and encoding engine Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2023-09-26 14:23 Dan Carpenter
2023-09-26 14:23 ` Dan Carpenter
2023-09-27  8:04 ` Hans Verkuil
2023-09-27  8:04   ` Hans Verkuil
2023-09-27  8:36   ` Dan Carpenter
2023-09-27  8:36     ` Dan Carpenter
2023-09-27 12:09     ` Kun-Fa Lin
2023-09-27 12:09       ` Kun-Fa Lin

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.