All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Felipe Balbi <balbi@kernel.org>,
	alsa-devel@alsa-project.org,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Cezary Rojewski <cezary.rojewski@intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Mark Brown <broonie@kernel.org>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Bard Liao <yung-chuan.liao@linux.intel.com>
Subject: Re: [PATCH 00/11] ALSA: PCM state reference optimization
Date: Tue, 27 Sep 2022 08:26:11 +0200	[thread overview]
Message-ID: <87h70tgwos.wl-tiwai@suse.de> (raw)
In-Reply-To: <YzJQP26l3k7yrTrs@workstation>

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

  reply	other threads:[~2022-09-27  6:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 13:55 [PATCH 00/11] ALSA: PCM state reference optimization Takashi Iwai
2022-09-26 13:55 ` [PATCH 01/11] ALSA: pcm: Avoid reference to status->state Takashi Iwai
2022-09-26 13:55 ` [PATCH 02/11] ALSA: pcm: Make mmap status read-only Takashi Iwai
2022-09-26 13:55 ` [PATCH 03/11] ALSA: aloop: Replace runtime->status->state reference to runtime->state Takashi Iwai
2022-09-26 13:55 ` [PATCH 04/11] ALSA: firewire: " Takashi Iwai
2022-09-26 13:55 ` [PATCH 05/11] ALSA: hda: " Takashi Iwai
2022-09-26 13:55 ` [PATCH 06/11] ALSA: asihpi: " Takashi Iwai
2022-09-26 13:55 ` [PATCH 07/11] ALSA: usb-audio: " Takashi Iwai
2022-09-26 13:55 ` [PATCH 08/11] ALSA: usx2y: " Takashi Iwai
2022-09-26 13:55 ` [PATCH 09/11] ASoC: intel: " Takashi Iwai
2022-09-26 18:00   ` Mark Brown
2022-09-26 13:55 ` [PATCH 10/11] ASoC: sh: " Takashi Iwai
2022-09-26 18:01   ` Mark Brown
2022-09-26 13:55 ` [PATCH 11/11] usb: gadget: " Takashi Iwai
2022-09-26 14:05   ` Greg Kroah-Hartman
2022-09-26 15:56 ` [PATCH 00/11] ALSA: PCM state reference optimization Jaroslav Kysela
2022-09-26 16:05   ` Takashi Iwai
2022-09-27  1:22 ` Takashi Sakamoto
2022-09-27  6:26   ` Takashi Iwai [this message]
2022-09-27 14:25     ` Takashi Sakamoto

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=87h70tgwos.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=balbi@kernel.org \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=o-takashi@sakamocchi.jp \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=yung-chuan.liao@linux.intel.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.