From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5558EC433ED for ; Thu, 20 May 2021 08:11:17 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 512E861059 for ; Thu, 20 May 2021 08:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 512E861059 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 17D961679; Thu, 20 May 2021 10:10:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 17D961679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621498273; bh=caCNJNxwElmd79REFBPDMoOmWngEtAmzvpcRv+lVPug=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dj9/tUEFn5iqquRxR7qyzkMwL/hbjJ3MdOnwwLks0JOgs5Hs+kF5F7f+A3o5UEFi3 PAQS76/UShczrtg3mh2CmgZ13mvsweC2vZ10w2bEpd5H/g2ac6RNtHrQys9i1HCsFF sMZ864LCBMFD6QARfNmLW91w7Uh1uRfacgfTGVkQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B6FFDF80127; Thu, 20 May 2021 10:10:22 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BAE05F80229; Thu, 20 May 2021 10:10:21 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BAB07F8020B for ; Thu, 20 May 2021 10:10:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BAB07F8020B X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 10F3EAEAB; Thu, 20 May 2021 08:10:15 +0000 (UTC) Date: Thu, 20 May 2021 10:10:13 +0200 Message-ID: From: Takashi Iwai To: ew.kim@samsung.com Subject: Re: [PATCH] ALSA: pcm: Need to check whether runtime is valid or not In-Reply-To: <1613950742.4603319.1621466175888@mail-kr2-3> References: <20210512044323.106673-1-chanho61.park@samsung.com> <20210512075834epcms2p182290868ca278decaa7e86c67f740db8@epcms2p1> <929757006.2969317.1620858694065@mail-kr2-3> <1932109751.3301982.1620952404404@mail-kr2-3> <1613950742.4603319.1621466175888@mail-kr2-3> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 20 May 2021 01:16:15 +0200, EUNWOO KIM wrote: > > > > > Sender : Takashi Iwai > > > > > 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 > > > > > > > > > > > > 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