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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B024EC54EE9 for ; Tue, 27 Sep 2022 06:27:10 +0000 (UTC) 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 DAB4B825; Tue, 27 Sep 2022 08:26:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DAB4B825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1664260027; bh=71PnI5uEeaoRM/3WmjjajQmBqLbb1aYB3tx5r1+1YJ8=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XTe0/sjZTIZ9J+taRgPpd4CEcGzvEDlAitcNeywukcPph15FaeFlWchSELbsQR7Lh Oa57eUwqK61Y6FgkLL715inlkBlzu7CyOhINntULAif6jZE20S93YvDQjeXFClNV5r njh7BWaDRufJcdELhTZQ9btSI7gEyFqC+60/lHr0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 611E0F8024C; Tue, 27 Sep 2022 08:26:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2A65EF8025E; Tue, 27 Sep 2022 08:26:16 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 29BC7F80166 for ; Tue, 27 Sep 2022 08:26:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 29BC7F80166 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HU9XjsWs"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="G+gZtmsI" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7B8301FA40; Tue, 27 Sep 2022 06:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664259972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MdFl7N6yTBaYGPuLpPaLynnSa4SsB8nBnCi4kklvaPk=; b=HU9XjsWsBhBB/U4AmLUEkq0+YgIgQ77C0xDSQ/lKFxPcTRtT/wRESuQW9VSpXiYnySQ+fc 4jU15lvgZ6wElphlTvv5jXQT4D69ueyTcmLVFbHYDvr/KUzcfLj9geLLkhxDb7onjr3+kk E/LdRvicvcc48dGU+teyKpTGzLt/fs8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664259972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MdFl7N6yTBaYGPuLpPaLynnSa4SsB8nBnCi4kklvaPk=; b=G+gZtmsIdihPM5qKnMreX1mag4YdQVAsLDajJ9VMdHO6dITg2dyNh4rov+TWhHGleJAJnj +ZBs1Rc+o8ypGsAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3E435139B3; Tue, 27 Sep 2022 06:26:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2J5vDoSXMmM6XwAAMHmgww (envelope-from ); Tue, 27 Sep 2022 06:26:12 +0000 Date: Tue, 27 Sep 2022 08:26:11 +0200 Message-ID: <87h70tgwos.wl-tiwai@suse.de> From: Takashi Iwai To: Takashi Sakamoto Subject: Re: [PATCH 00/11] ALSA: PCM state reference optimization In-Reply-To: References: <20220926135558.26580-1-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Cc: Felipe Balbi , alsa-devel@alsa-project.org, Kai Vehmanen , Greg Kroah-Hartman , Peter Ujfalusi , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Mark Brown , Ranjani Sridharan , Bard Liao 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 Tue, 27 Sep 2022 03:22:07 +0200, Takashi Sakamoto wrote: > > Hi, > > On Mon, Sep 26, 2022 at 03:55:47PM +0200, Takashi Iwai wrote: > > Hi, > > > > this is a patch set for simplifying the reference to the current PCM > > state by having the local copy in runtime instead of relying on > > runtime->status indirection. This also hardens against the attack by > > modifying the mmapped status record. > > The overall patches looks good to me and I have no objections, while I > have some slight opinions to them in a place of sound driver developer. > > > The first patch does the basic job in the core PCM side, > > The main concern is indirect accessing to state field via some pointer > hops. I think addition of helper macro at first step eases centre of your > work, like: > > ``` > diff --git a/include/sound/pcm.h b/include/sound/pcm.h > index 8c48a5bce88c..f6a160cb8135 100644 > --- a/include/sound/pcm.h > +++ b/include/sound/pcm.h > @@ -669,6 +669,20 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream, > stream <= SNDRV_PCM_STREAM_LAST; \ > stream++) > > +/** > + * snd_pcm_stream_state - Return state in runtime of the PCM substream. > + * @substream: substream to check. runtime should be attached. > + * > + * Return state in runtime of the PCM substream. The substream should exists and > + * runtime should be attached to it. > + */ > +static inline snd_pcm_state_t snd_pcm_stream_state(const snd_pcm_substream *substream) > +{ > + snd_BUG_ON(!(sub) || !(sub)->runtime); > + > + return substream->runtime->status->state; > +} > ``` > > As we can see, sound driver programmer sometimes checks state of runtime > in their code, thus the macro could helps them as well as centre of your > change. This might help if we may need any change in future again. But the NULL check is superfluous in most places, and the state check is done often in a hot path, it's better to rip off. So it's only about the read of runtime->state, and then it's doubtful whether it brings much value at this moment; that's the reason I didn't introduce such a macro for now. Takashi