From: Joonho Lee <[email protected]>

The staged virtio-snd capture path needs to sample stop_threshold from
completion context to distinguish free-running capture from bounded
capture. Software parameters can update this field while capture runs.

Mark the runtime stop-threshold assignments with WRITE_ONCE and the proc
status read with READ_ONCE. This pairs the assignments with the driver's
staged-capture policy sampling.

These annotations do not provide a transaction for the entire sw_params
update. The driver serializes its cached policy and accounting with its
own substream lock.

Assisted-by: LLM
Signed-off-by: Joonho Lee <[email protected]>
---
 sound/core/oss/pcm_oss.c | 2 +-
 sound/core/pcm.c         | 3 ++-
 sound/core/pcm_native.c  | 5 +++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index e8df27d09b97..897c8dddcfd2 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -2958,7 +2958,7 @@ static int snd_pcm_oss_mmap(struct file *file, struct 
vm_area_struct *area)
               runtime->oss.mmap_bytes);
 #endif
        /* In mmap mode we never stop */
-       runtime->stop_threshold = runtime->boundary;
+       WRITE_ONCE(runtime->stop_threshold, runtime->boundary);
 
        return 0;
 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 064df4cd3b50..356ddaf33f63 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -422,7 +422,8 @@ static void snd_pcm_substream_proc_sw_params_read(struct 
snd_info_entry *entry,
        snd_iprintf(buffer, "period_step: %u\n", runtime->period_step);
        snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min);
        snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold);
-       snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold);
+       snd_iprintf(buffer, "stop_threshold: %lu\n",
+                   READ_ONCE(runtime->stop_threshold));
        snd_iprintf(buffer, "silence_threshold: %lu\n", 
runtime->silence_threshold);
        snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size);
        snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 35152fae74ca..a2ea44c3c1d2 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -871,7 +871,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream 
*substream,
        runtime->period_step = 1;
        runtime->control->avail_min = runtime->period_size;
        runtime->start_threshold = 1;
-       runtime->stop_threshold = runtime->buffer_size;
+       WRITE_ONCE(runtime->stop_threshold, runtime->buffer_size);
        runtime->silence_threshold = 0;
        runtime->silence_size = 0;
        runtime->boundary = runtime->buffer_size;
@@ -1062,7 +1062,8 @@ static int snd_pcm_sw_params(struct snd_pcm_substream 
*substream,
                runtime->period_step = params->period_step;
                runtime->control->avail_min = params->avail_min;
                runtime->start_threshold = params->start_threshold;
-               runtime->stop_threshold = params->stop_threshold;
+               /* Drivers may sample the stop policy from completion context. 
*/
+               WRITE_ONCE(runtime->stop_threshold, params->stop_threshold);
                runtime->silence_threshold = params->silence_threshold;
                runtime->silence_size = params->silence_size;
                params->boundary = runtime->boundary;

-- 
Git-157)



Reply via email to