All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: ew.kim@samsung.com
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] ALSA: pcm: Need to check whether runtime is valid or not
Date: Thu, 20 May 2021 10:10:13 +0200	[thread overview]
Message-ID: <s5hsg2hhllm.wl-tiwai@suse.de> (raw)
In-Reply-To: <1613950742.4603319.1621466175888@mail-kr2-3>

On Thu, 20 May 2021 01:16:15 +0200,
EUNWOO KIM wrote:
> 
> > > > Sender : Takashi Iwai <tiwai@suse.de>
> 
> > > > Date : 2021-05-12 16:08 (GMT+9)
> 
> > > > Title : Re: [PATCH]
>  ALSA: pcm: Need to check whether runtime is valid or not
> 
> > > >  
> 
> > > > On Wed, 12 May 2021 06:43:23 +0200,
> 
> > > > Chanho Park wrote:
> 
> > > > > 
> 
> > > > > From: eunwoo kim <ew.kim@samsung.com>
> 
> > > > > 
> 
> > > > > Since snd_pcm_ioctl_sw_params_compat has no runtime variable check,
> 
> > > > > if application call the ioctl after close, it can make kernel crash.
> 
> > > > > So, snd_pcm_ioctl_sw_params_compat needs to check the runtime variable
> 
> > > > > at the beginning of the function.
> 
> > > >  
> 
> > > > > In principle, you cannot call ioctl for an already closed file.
> 
> > > > > Or do you mean other code path?
> 
> > > > 
> 
> > > > Yes, other code path such as application layer or alsa framwork layer.
> 
> > >  
> 
> > > But how can it go over the 32bit compat ioctl layer...?
> 
> > > It's always tied with a file object, so the runtime object is
> 
> > > assured.
> 
> > > 
> 
> > > > >
>  Yes, I think so too. but in fact, some case can call 32bit compat ioctl.
> 
> > >  
> 
> > > >
>  In our case, suspend call is releasing all running pcm device. other side some application want to start music.
> 
> > > > it make critical section between suspend and pcm_open from application.
> 
> > > > this is error and we have to solve this problem without this patch.
> 
> > > >
>  but I think kernel don't make kernel crash even if application or system architecture have problem.
> 
> > >  
> 
> > > I guess you're scratching a wrong surface.
> 
> > > 
> 
> > > > could you tell me more detail? why do you think that.
> 
> > > >
>  In 64bit native case, it didn't make kernel crash on same test case. because native always check runtime in ioctl.
> 
> >  
> 
> > > Try to put WARN_ON() there.  If you can catch the real case, it'd be
> 
> > > worth to merge.  Otherwise, it's just a wrong place to look at.
> 
> > 
> 
> >
>  I already found root cause in our issue case. And I am fixing this issue via changing sequence.
> 
> > 
> 
> > I think that you want to know issue case because why this patch need.
> 
> > So I explain more about our case.
> 
> > 1. application playback sound in android.
> 
> > 2. call pcm_open in tinyalsa.
> 
> > 3. call file open and hw param in pcm_open
> 
> > 4. go to suspend 
> 
> > 5. freezing all task before calling sw param in pcm_open.
> 
> > 6. kernel layer try to go suspend
> 
> >
>  7. release all running substream, because all HW IPs must to go idle for power save mode.
> 
> > -> detach runtime from substream.
> 
> > 8. go to resume.
> 
> > 9. call sw param in pcm_open.
> 
> > 10-1. native case : has runtime check in ioctl -> return error ->
>  audio hal layer recovery hw connect.
> 
> > 10-2. 32bit compat case : has not runtime check -> runtime is not valid ->
>  make kernel crash.
> 
> > 
> 
> >
>  - if AAOS can support wakelock, we can postpone suspend until finished pcm_open. but AAOS didn't support wakelock.
> 
> > I'm afraid that the approach is wrong.  It breaks the fundamental PCM
> 
> > state change rule.
> 
> Yes, that is wrong approach I know. So I am changing that.
> 
> > I guess it's a downstream driver that does that?  If so, tweaking
> 
> > something superfluous in the upstream code is unacceptable.
> 
> > BTW, if you want further discussions, please don't drop Cc to
> 
> > alsa-devel ML.
> 
> Safety is very important in automotive. so it must not to make kernel crash
> even if someone make wrong code. because it can connect to accident.

Shipping such a broken stuff on the car would be a more serious
problem.  Really.  If this kind of change is required, it means that
the driver has a fundamental design problem.

A wrong driver code can always crash a kernel, no matter how the core
stuff is written.  So, it might make sense to put some debug code, but
it'd be not meant as a "fix" but only for debugging.

> If 32bit compat don't need checking-runtime, why do pcm_native check runtime?

That code path can be called from OSS layer, so it's more complex.
We may drop the check as well, of course.  It's no mandatory check at
all.


Takashi

  reply	other threads:[~2021-05-20  8:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210512044441epcas2p4ad7c01a1dc9048bd96a9973760017d8c@epcas2p4.samsung.com>
2021-05-12  4:43 ` [PATCH] ALSA: pcm: Need to check whether runtime is valid or not Chanho Park
2021-05-12  7:08   ` Takashi Iwai
     [not found]   ` <20210512075834epcms2p182290868ca278decaa7e86c67f740db8@epcms2p1>
     [not found]     ` <929757006.2969317.1620858694065@mail-kr2-3>
     [not found]       ` <1932109751.3301982.1620952404404@mail-kr2-3>
     [not found]         ` <CGME20210512044441epcas2p4ad7c01a1dc9048bd96a9973760017d8c@epcms2p1>
     [not found]           ` <s5h8s4hahxj.wl-tiwai@suse.de>
     [not found]             ` <s5ho8df9inv.wl-tiwai@suse.de>
2021-05-19 23:16             ` EUNWOO KIM
2021-05-20  8:10               ` Takashi Iwai [this message]
2021-05-24 22:41                 ` EUNWOO KIM
2021-05-25  6:51                   ` Jaroslav Kysela

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=s5hsg2hhllm.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=ew.kim@samsung.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.