From patchwork Tue Nov 12 15:16:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179218 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8257992ilf; Tue, 12 Nov 2019 07:18:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxbymRsavqSbKmScyUPgXPpM1DPMJ6+H4lDkF1NUbsv/od1HpPthfXJ+M/7pRhziDpx6yv/ X-Received: by 2002:a05:6402:488:: with SMTP id k8mr33193223edv.293.1573571924489; Tue, 12 Nov 2019 07:18:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571924; cv=none; d=google.com; s=arc-20160816; b=LEE7nwBwMVzdVVGudnQ+UfsSMwRMnDg8NMnGFIj7NOOIZs+vxWV6VNBxX0iDYoyLfe 6tK3MH2203c5djchvJdWViKgPDAVaVzDmdG5CfMMJrFMAYJvJoIBQTaW8mVCQZQeZzsV pcHfEjVD2RMcRFbrABNaADo58SJXnQ8OrXJ9CO9dudOHIWFXcUq/KQwrzHXS47+7jb9I J5ZP6sqVwfbajQxnZB2sYUB0DCkNBxJnwUwYFzv0yW/a5t1U7AiKxeFGEodctu6ak/ll I+PxI0pWZ4W5iKrAGrihJuW1Z6MrXP68mE+uwdO7v7HIC6HzHUct9qb3eKUvuR6CUjtE KKhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4IdFaUcOQg+fOOth3F8jTxHO76Ysi84y04rDgksBUV8=; b=jUd0zEWRMtBht5nnk68rxEy1/USsx8/MaR+/xcZHnrQHmcIie1Z8JMVe8aY4anv5q6 EdHahq5QKLsvB/bTEab41d0CaU3b9yDB45ARQO9Uat9682erHkt8Q+VDpTxBX+X49aR4 gNIwBWrc5QDPDR0a+04e0k7LTVdL3qf1sOfVeyZxfei8a3EvSqwolI/6Hz2niejKWY6k cMbT12K/Wgwvv53cjAJ6GIiSbzIy9efFtPJZqy4+46t+aeV3j3XSRHJLRq1pPuwVZW2m 86YvLlAxcPo4CFJtRLL0idqJ1XKc3hjR/klzItUp5Wzi5+wJ2YTeg3YMNaCWbe0mCxDl 5jrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.40; Tue, 12 Nov 2019 07:18:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727310AbfKLPSd (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:33 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:45483 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727046AbfKLPSb (ORCPT ); Tue, 12 Nov 2019 10:18:31 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MJV9S-1iAfZo27Y0-00JoSP; Tue, 12 Nov 2019 16:16:56 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 1/8] ALSA: Replace timespec with timespec64 Date: Tue, 12 Nov 2019 16:16:35 +0100 Message-Id: <20191112151642.680072-2-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:WutTGrm8YjipYtkNStZpr84C73pW7VkBlcuOuxEj8qmXgAOvDXH 96RXaseh4MFIQSsF5cDWxpmxrclg55XfV6EHgyTjz+z9ITMnzQs6MbSQp6FS2moIIS7vMA7 MOpB25WfHG5Y170lAko7LkUnOZLZNx2PkEp2S81Sp/ffNI1ryUrccg23WWQLIpYXb5a+d/A KdqEzE1V4royyRdnNbg6w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:Wojcc0ZhKTk=:Cij90ck/B4X8fJmAXczFrN zEUfNxbyCBhcndv6oBIJzjf+NtGEnCX+simnWEQuVQMtJTvx5AXFrglNc4ix7PgSehlkKBLwu pzyi0G0eCq7MYz581qvNvLTMBwMaOVSZDXdpsiJGpR4Wy2zPyaNxTEDMs5fwu6qcsKk4/kVu5 kEGQ9u1av8bmfZOPV3w3OJk4cpQF3CZQQqoltu7krhwZ/IZpzS+QfW/lWUM9hkSFnoHXpaUuu AU+mYlFuosylVj7vMEMKYvl7NA5emNlhyBeq8faRu94l69vUIMdXMhdFCiXLYhnRz1zgG33Kn pCfpO2VprIrTZua6P/g8HUgAfP3eW7wzZACm85aOfuqGeJ+uewc8jSEgvT/ciLUI7E2yMEZSG fH4he29FsX3wcCrPsamxDLguG97ERqUJaxyBbyTmRxKcg/1Uc8pCCFUn8uKbUCn02teDdmQF9 fK84PLYnom4uXqFa95ImEw12AFpmE+RmOSxu/Qm5PS7+YHRHDF5GcySNUV53gqiNRMfvnq8SO H8Ctq80iJ2NhTO0xusA/NCDwdCtyBC/W7hQY9Kjo9xKvvlXhjLcqQrWYdAA+mvxwmgxhTwV3C FxTgeQt4IrUoLYLBQL0eg8EEi/nO8bzgx5Pg+Vnaj1PhfgRrytWdfDaViEPtkTYLa2hOXLFfs IXMvfEU8xfg4nZ5hCfVOlNfz+MQjKplQjFrALcAzUEIKSdEDv+ub87QJpcqVTmVcnLC2yPlOZ 4IGnB0GYpx76QbFtVeWNo0N4NMMaNBPT/6lY4Ggs47YXNnaiVqv8rIl/GOZl3EUJx1uRftFx4 25DiZZ2E5BZLjZ1223BH2vt98Aum1rCu+AVVv/3gjepBZ48YUt1/Gn17Rs32qpR6WkxbkouRK NI4ETZKe05JR8yIhfdPQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang Since timespec is not year 2038 safe on 32bit system, and we need to convert all timespec variables to timespec64 type for sound subsystem. This patch is used to do preparation for following patches, that will convert all structures defined in uapi/sound/asound.h to use 64-bit time_t. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/sound/pcm.h | 18 ++++++++-------- include/sound/timer.h | 4 ++-- sound/core/pcm_lib.c | 36 +++++++++++++++++++------------ sound/core/pcm_native.c | 12 +++++++---- sound/core/timer.c | 28 ++++++++++++------------ sound/pci/hda/hda_controller.c | 10 ++++----- sound/soc/intel/skylake/skl-pcm.c | 4 ++-- 7 files changed, 62 insertions(+), 50 deletions(-) -- 2.20.0 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index bbe6eb1ff5d2..2665b3dc15e8 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -61,7 +61,7 @@ struct snd_pcm_ops { int (*trigger)(struct snd_pcm_substream *substream, int cmd); snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream); int (*get_time_info)(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report); int (*fill_silence)(struct snd_pcm_substream *substream, int channel, @@ -342,7 +342,7 @@ static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy struct snd_pcm_runtime { /* -- Status -- */ struct snd_pcm_substream *trigger_master; - struct timespec trigger_tstamp; /* trigger timestamp */ + struct timespec64 trigger_tstamp; /* trigger timestamp */ bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */ int overrange; snd_pcm_uframes_t avail_max; @@ -418,7 +418,7 @@ struct snd_pcm_runtime { /* -- audio timestamp config -- */ struct snd_pcm_audio_tstamp_config audio_tstamp_config; struct snd_pcm_audio_tstamp_report audio_tstamp_report; - struct timespec driver_tstamp; + struct timespec64 driver_tstamp; #if IS_ENABLED(CONFIG_SND_PCM_OSS) /* -- OSS things -- */ @@ -1151,22 +1151,22 @@ static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substrea } /** - * snd_pcm_gettime - Fill the timespec depending on the timestamp mode + * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode * @runtime: PCM runtime instance - * @tv: timespec to fill + * @tv: timespec64 to fill */ static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime, - struct timespec *tv) + struct timespec64 *tv) { switch (runtime->tstamp_type) { case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC: - ktime_get_ts(tv); + ktime_get_ts64(tv); break; case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW: - getrawmonotonic(tv); + ktime_get_raw_ts64(tv); break; default: - getnstimeofday(tv); + ktime_get_real_ts64(tv); break; } } diff --git a/include/sound/timer.h b/include/sound/timer.h index 199c36295a0d..357e30983284 100644 --- a/include/sound/timer.h +++ b/include/sound/timer.h @@ -89,7 +89,7 @@ struct snd_timer_instance { unsigned long ticks, unsigned long resolution); void (*ccallback) (struct snd_timer_instance * timeri, int event, - struct timespec * tstamp, + struct timespec64 * tstamp, unsigned long resolution); void (*disconnect)(struct snd_timer_instance *timeri); void *callback_data; @@ -113,7 +113,7 @@ struct snd_timer_instance { */ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer); -void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp); +void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp); int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer); int snd_timer_global_free(struct snd_timer *timer); int snd_timer_global_register(struct snd_timer *timer); diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index d80041ea4e01..42cc1b71d1e3 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -144,8 +144,12 @@ void __snd_pcm_xrun(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; trace_xrun(substream); - if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) - snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp); + if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { + struct timespec64 tstamp; + + snd_pcm_gettime(runtime, &tstamp); + runtime->status->tstamp = timespec64_to_timespec(tstamp); + } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { char name[16]; @@ -200,12 +204,12 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream, } static void update_audio_tstamp(struct snd_pcm_substream *substream, - struct timespec *curr_tstamp, - struct timespec *audio_tstamp) + struct timespec64 *curr_tstamp, + struct timespec64 *audio_tstamp) { struct snd_pcm_runtime *runtime = substream->runtime; u64 audio_frames, audio_nsecs; - struct timespec driver_tstamp; + struct timespec64 driver_tstamp; if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE) return; @@ -229,18 +233,22 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, } audio_nsecs = div_u64(audio_frames * 1000000000LL, runtime->rate); - *audio_tstamp = ns_to_timespec(audio_nsecs); + *audio_tstamp = ns_to_timespec64(audio_nsecs); } - if (!timespec_equal(&runtime->status->audio_tstamp, audio_tstamp)) { - runtime->status->audio_tstamp = *audio_tstamp; - runtime->status->tstamp = *curr_tstamp; + + if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || + runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { + runtime->status->audio_tstamp = + timespec64_to_timespec(*audio_tstamp); + runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); } + /* * re-take a driver timestamp to let apps detect if the reference tstamp * read by low-level hardware was provided with a delay */ - snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp); + snd_pcm_gettime(substream->runtime, &driver_tstamp); runtime->driver_tstamp = driver_tstamp; } @@ -253,8 +261,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, snd_pcm_sframes_t hdelta, delta; unsigned long jdelta; unsigned long curr_jiffies; - struct timespec curr_tstamp; - struct timespec audio_tstamp; + struct timespec64 curr_tstamp; + struct timespec64 audio_tstamp; int crossed_boundary = 0; old_hw_ptr = runtime->status->hw_ptr; @@ -277,9 +285,9 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */ if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT) - snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); + snd_pcm_gettime(runtime, &curr_tstamp); } else - snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); + snd_pcm_gettime(runtime, &curr_tstamp); } if (pos == SNDRV_PCM_POS_XRUN) { diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 91c6ad58729f..7d0fe30f1658 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -879,12 +879,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream, status->suspended_state = runtime->status->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; - status->trigger_tstamp = runtime->trigger_tstamp; + status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp); if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp = runtime->status->tstamp; - status->driver_tstamp = runtime->driver_tstamp; + status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp); status->audio_tstamp = runtime->status->audio_tstamp; if (runtime->audio_tstamp_report.valid == 1) @@ -897,8 +897,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream, } } else { /* get tstamp only in fallback mode and only if enabled */ - if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) - snd_pcm_gettime(runtime, &status->tstamp); + if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { + struct timespec64 tstamp; + + snd_pcm_gettime(runtime, &tstamp); + status->tstamp = timespec64_to_timespec(tstamp); + } } _tstamp_end: status->appl_ptr = runtime->control->appl_ptr; diff --git a/sound/core/timer.c b/sound/core/timer.c index 5c9fbf3f4340..29b99cfb5215 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -59,7 +59,7 @@ struct snd_timer_user { spinlock_t qlock; unsigned long last_resolution; unsigned int filter; - struct timespec tstamp; /* trigger tstamp */ + struct timespec64 tstamp; /* trigger tstamp */ wait_queue_head_t qchange_sleep; struct fasync_struct *fasync; struct mutex ioctl_lock; @@ -450,12 +450,12 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event) struct snd_timer *timer = ti->timer; unsigned long resolution = 0; struct snd_timer_instance *ts; - struct timespec tstamp; + struct timespec64 tstamp; if (timer_tstamp_monotonic) - ktime_get_ts(&tstamp); + ktime_get_ts64(&tstamp); else - getnstimeofday(&tstamp); + ktime_get_real_ts64(&tstamp); if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START || event > SNDRV_TIMER_EVENT_PAUSE)) return; @@ -1022,7 +1022,7 @@ static int snd_timer_dev_disconnect(struct snd_device *device) return 0; } -void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp) +void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp) { unsigned long flags; unsigned long resolution = 0; @@ -1315,7 +1315,7 @@ static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu, static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, int event, - struct timespec *tstamp, + struct timespec64 *tstamp, unsigned long resolution) { struct snd_timer_user *tu = timeri->callback_data; @@ -1329,7 +1329,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, return; memset(&r1, 0, sizeof(r1)); r1.event = event; - r1.tstamp = *tstamp; + r1.tstamp = timespec64_to_timespec(*tstamp); r1.val = resolution; spin_lock_irqsave(&tu->qlock, flags); snd_timer_user_append_to_tqueue(tu, &r1); @@ -1352,7 +1352,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, { struct snd_timer_user *tu = timeri->callback_data; struct snd_timer_tread *r, r1; - struct timespec tstamp; + struct timespec64 tstamp; int prev, append = 0; memset(&r1, 0, sizeof(r1)); @@ -1365,14 +1365,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, } if (tu->last_resolution != resolution || ticks > 0) { if (timer_tstamp_monotonic) - ktime_get_ts(&tstamp); + ktime_get_ts64(&tstamp); else - getnstimeofday(&tstamp); + ktime_get_real_ts64(&tstamp); } if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { r1.event = SNDRV_TIMER_EVENT_RESOLUTION; - r1.tstamp = tstamp; + r1.tstamp = timespec64_to_timespec(tstamp); r1.val = resolution; snd_timer_user_append_to_tqueue(tu, &r1); tu->last_resolution = resolution; @@ -1386,14 +1386,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->tqueue[prev]; if (r->event == SNDRV_TIMER_EVENT_TICK) { - r->tstamp = tstamp; + r->tstamp = timespec64_to_timespec(tstamp); r->val += ticks; append++; goto __wake; } } r1.event = SNDRV_TIMER_EVENT_TICK; - r1.tstamp = tstamp; + r1.tstamp = timespec64_to_timespec(tstamp); r1.val = ticks; snd_timer_user_append_to_tqueue(tu, &r1); append++; @@ -1871,7 +1871,7 @@ static int snd_timer_user_status(struct file *file, if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); - status.tstamp = tu->tstamp; + status.tstamp = timespec64_to_timespec(tu->tstamp); status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 6387c7e90918..d4620b0561e9 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -491,7 +491,7 @@ static inline bool is_link_time_supported(struct snd_pcm_runtime *runtime, } static int azx_get_time_info(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { @@ -511,7 +511,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, if (audio_tstamp_config->report_delay) nsec = azx_adjust_codec_delay(substream, nsec); - *audio_ts = ns_to_timespec(nsec); + *audio_ts = ns_to_timespec64(nsec); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ @@ -528,16 +528,16 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, return -EINVAL; case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW: - *system_ts = ktime_to_timespec(xtstamp.sys_monoraw); + *system_ts = ktime_to_timespec64(xtstamp.sys_monoraw); break; default: - *system_ts = ktime_to_timespec(xtstamp.sys_realtime); + *system_ts = ktime_to_timespec64(xtstamp.sys_realtime); break; } - *audio_ts = ktime_to_timespec(xtstamp.device); + *audio_ts = ktime_to_timespec64(xtstamp.device); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED; diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c index 7f287424af9b..17b7bacf1e2c 100644 --- a/sound/soc/intel/skylake/skl-pcm.c +++ b/sound/soc/intel/skylake/skl-pcm.c @@ -1246,7 +1246,7 @@ static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream, } static int skl_get_time_info(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { @@ -1264,7 +1264,7 @@ static int skl_get_time_info(struct snd_pcm_substream *substream, if (audio_tstamp_config->report_delay) nsec = skl_adjust_codec_delay(substream, nsec); - *audio_ts = ns_to_timespec(nsec); + *audio_ts = ns_to_timespec64(nsec); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */ From patchwork Tue Nov 12 15:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179222 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8258461ilf; Tue, 12 Nov 2019 07:19:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxG8eP5Fvn+GK1GfPkzOOsZQrNE1txuiNUcixK5y3QzrH9PczeNmEtk6sSoQ8WsiJTSRdlv X-Received: by 2002:a17:906:f109:: with SMTP id gv9mr29250574ejb.196.1573571947589; Tue, 12 Nov 2019 07:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571947; cv=none; d=google.com; s=arc-20160816; b=rY6CO9AXhhuHIwhOF6wqJHhD9Yi1jQm5V7ND81UEQyQtfpCWYd32daDL0X9EzZyDo9 r4/J4nEJbsGlYjaT5AinQC7/d86q92E0lsRXrcv78VeDOinFAUeKSI6RZqYmzcvo1fEg bc0/JuYiWbwabzO3HUonehOmZfsl9vGEhB3SaLhasd0/GfSPWQN6nsq5du+GSX0XBWoe 39oefOxdAy8utUdeoV3KIE1rwGb7vrmRF2KOALe27vEXUCGtbkNUNW8wJNbsErHzcuIj gkrCuzo6JSlXmYcPYPHxHou2Y1bOAXJycu+E4JIQWqF1FXyqh3ZwwrrkcZ5V05T15kmq a8Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RMr5XLGGfmcYzoJ+KmfQIaEE9Vd4oaqrnjTyjxvFhVs=; b=QtxbKV3ewqm3uHGTGO70rFrh7ODDqIPCekhwG0ZOa6L05HQX1pVskHQHe42Mzahxfy 8imj6cS8zZVpYrkdhscnO4b+qYH+hSOCZU9PriWgVlSHltaXian/cXWQrXsxX5+HariX X868w5OVAPnURfZ0Ug+0O7sEGkmmM9IgMznlMUiFhbQd7kaX3J3gz6BHvaHYgiZ1C0dj PKybV2SGw5XiUgOuYq2u4LQHHVYIjNWHswqWtrEnK31SlYvHKe3dVgb9N5mnRp5YPoYc Pa/zCTyzVFRrEapcyWJQlyu9XhawV77kDKo6dYqvndjRuMY8GpQpCurI/OcpoGefgVo3 urOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.19.02; Tue, 12 Nov 2019 07:19:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbfKLPS5 (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:57 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:43659 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbfKLPSz (ORCPT ); Tue, 12 Nov 2019 10:18:55 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MtfRp-1hc9qB3Td1-00v4Hm; Tue, 12 Nov 2019 16:16:56 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 2/8] ALSA: Avoid using timespec for struct snd_timer_status Date: Tue, 12 Nov 2019 16:16:36 +0100 Message-Id: <20191112151642.680072-3-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:u3zGZYSUP0mPAgM1xzr7VtvAdHVSHJvfYGEoRMDWeoYEsEXXSCB 2a0XtIGPepntRjOYl5w4Uldg2inkkpHr7o6pFEbF5HT2hRsNg7aXA3oDJNmCaGwhGoL3t/+ lGn4c4O/jnzvkUwsfEbgxExa7aXDXwwP9a3V+wpaGSc+tQZ7WdA3ewmWhtXZ0FRKVeACN96 nJRGS96Mosu+p5pjnnX9A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:0XEazvyASJg=:SlRb9zMUQw9OFLamESQKxP 2TmH0aE8/RWYsoFgTzFlQQS3pH+9z+x3SZehXXxaNvj3GYpBNc+O6OcFPDcgeL0Gr61a9JkTC HYQQ/TwBokGTfZ147wNjak5exIJA2RvU+6Qk0u+lsM/hHTVKG36ytF7vOx+sOeBJSSvqFZ/+u CxybcpN5DiDVyLVZYxYoHz53HXxuRSoLLwqGjPEOgV62zMBMiHZ8LBvp/kSDDpYxbh4miTKrl tsYss2hinqfrsqrNb94lQLxU47ULfqkk5yqVoIIKgRnA2ITPdSdnsx+XJf0NYyx9hvOq86c9+ FL9eBfolGHAYi2aP0YnPn8bcYuL/WzU3IFBJF7jst0CGKUJ935HR8x/L2N40wsSKv/bM/QFar wsv1kvP9fns4sbdEa/XoToWzXV4s3lh9zfAqzQVwBKf1sJ35p2oiZkcTKbarnF49s9G0RwxRi iAaen3Bw6MiPop4I6NmMAkzDZjDEl0YRL3ZDo8sSxVi1585jRY5QBH41fGfg70PiiXVbuW4dD nvMsPbNGKM7ogdwwHrIqPH9wcDZGXXDhNVlSkR/DjCT4/j/dHK7trAKfrUTZkgPz59498uQV4 LgzrbIyipsphKjESiEIW3+yDphXaJnwwQsEfOrU3gKtTI2XZIKFrWEPVbaacX3qvTOathYqPr jj4pOSZEPzeIrP7QjcCqRJn3ENsQogP0u1rsuUZ+E8Cb8Ipi6Gm6vDCdWKW3OislxSEU/qYQK s3ZoXTKSDz99GsC773JSVv6MJZkkJzPrDWl7RXi4Tx+G6xsaue1Pe74OHsCpw1N/odwAeXc1I lqBwPjPyH7Uwtmt5OlFgHIzWUJqmMS313hQ2v+8VjA/H9Hk4hw3e/xX4Mppw3xB3WqGVgq8NL wneV/KLj/C5II6NQPFJQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang struct snd_timer_status uses 'timespec' type variables to record timestamp, which will be changed to an incompatible layout with updated user space using 64-bit time_t. To handle both the old and the new layout on 32-bit architectures, this patch introduces 'struct snd_timer_status32' and 'struct snd_timer_status64' to handle 32bit time_t and 64bit time_t in native mode and compat mode, which replaces timespec with s64 type. When glibc changes time_t to 64-bit, any recompiled program will issue ioctl commands that the kernel does not understand without this patch. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 2 ++ sound/core/timer.c | 62 +++++++++++++++++++++++++++++++++---- sound/core/timer_compat.c | 57 ++++------------------------------ 3 files changed, 64 insertions(+), 57 deletions(-) -- 2.20.0 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index df1153cea0b7..930854f67fd3 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -761,6 +761,7 @@ struct snd_timer_params { unsigned char reserved[60]; /* reserved */ }; +#ifndef __KERNEL__ struct snd_timer_status { struct timespec tstamp; /* Timestamp - last update */ unsigned int resolution; /* current period resolution in ns */ @@ -769,6 +770,7 @@ struct snd_timer_status { unsigned int queue; /* used queue size */ unsigned char reserved[64]; /* reserved */ }; +#endif #define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int) #define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id) diff --git a/sound/core/timer.c b/sound/core/timer.c index 29b99cfb5215..921f4ae2f9bf 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -65,6 +65,30 @@ struct snd_timer_user { struct mutex ioctl_lock; }; +struct snd_timer_status32 { + s32 tstamp_sec; /* Timestamp - last update */ + s32 tstamp_nsec; + unsigned int resolution; /* current period resolution in ns */ + unsigned int lost; /* counter of master tick lost */ + unsigned int overrun; /* count of read queue overruns */ + unsigned int queue; /* used queue size */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_IOCTL_STATUS32 _IOR('T', 0x14, struct snd_timer_status32) + +struct snd_timer_status64 { + s64 tstamp_sec; /* Timestamp - last update */ + s64 tstamp_nsec; + unsigned int resolution; /* current period resolution in ns */ + unsigned int lost; /* counter of master tick lost */ + unsigned int overrun; /* count of read queue overruns */ + unsigned int queue; /* used queue size */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_IOCTL_STATUS64 _IOR('T', 0x14, struct snd_timer_status64) + /* list of timers */ static LIST_HEAD(snd_timer_list); @@ -1861,17 +1885,41 @@ static int snd_timer_user_params(struct file *file, return err; } -static int snd_timer_user_status(struct file *file, - struct snd_timer_status __user *_status) +static int snd_timer_user_status32(struct file *file, + struct snd_timer_status32 __user *_status) + { + struct snd_timer_user *tu; + struct snd_timer_status32 status; + + tu = file->private_data; + if (!tu->timeri) + return -EBADFD; + memset(&status, 0, sizeof(status)); + status.tstamp_sec = tu->tstamp.tv_sec; + status.tstamp_nsec = tu->tstamp.tv_nsec; + status.resolution = snd_timer_resolution(tu->timeri); + status.lost = tu->timeri->lost; + status.overrun = tu->overrun; + spin_lock_irq(&tu->qlock); + status.queue = tu->qused; + spin_unlock_irq(&tu->qlock); + if (copy_to_user(_status, &status, sizeof(status))) + return -EFAULT; + return 0; +} + +static int snd_timer_user_status64(struct file *file, + struct snd_timer_status64 __user *_status) { struct snd_timer_user *tu; - struct snd_timer_status status; + struct snd_timer_status64 status; tu = file->private_data; if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); - status.tstamp = timespec64_to_timespec(tu->tstamp); + status.tstamp_sec = tu->tstamp.tv_sec; + status.tstamp_nsec = tu->tstamp.tv_nsec; status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; @@ -1995,8 +2043,10 @@ static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd, return snd_timer_user_info(file, argp); case SNDRV_TIMER_IOCTL_PARAMS: return snd_timer_user_params(file, argp); - case SNDRV_TIMER_IOCTL_STATUS: - return snd_timer_user_status(file, argp); + case SNDRV_TIMER_IOCTL_STATUS32: + return snd_timer_user_status32(file, argp); + case SNDRV_TIMER_IOCTL_STATUS64: + return snd_timer_user_status64(file, argp); case SNDRV_TIMER_IOCTL_START: case SNDRV_TIMER_IOCTL_START_OLD: return snd_timer_user_start(file); diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index bb6be484dfd3..20eef5bc304b 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -69,54 +69,11 @@ static int snd_timer_user_info_compat(struct file *file, return 0; } -struct snd_timer_status32 { - struct compat_timespec tstamp; - u32 resolution; - u32 lost; - u32 overrun; - u32 queue; - unsigned char reserved[64]; -}; - -static int snd_timer_user_status_compat(struct file *file, - struct snd_timer_status32 __user *_status) -{ - struct snd_timer_user *tu; - struct snd_timer_status32 status; - - tu = file->private_data; - if (!tu->timeri) - return -EBADFD; - memset(&status, 0, sizeof(status)); - status.tstamp.tv_sec = tu->tstamp.tv_sec; - status.tstamp.tv_nsec = tu->tstamp.tv_nsec; - status.resolution = snd_timer_resolution(tu->timeri); - status.lost = tu->timeri->lost; - status.overrun = tu->overrun; - spin_lock_irq(&tu->qlock); - status.queue = tu->qused; - spin_unlock_irq(&tu->qlock); - if (copy_to_user(_status, &status, sizeof(status))) - return -EFAULT; - return 0; -} - -#ifdef CONFIG_X86_X32 -/* X32 ABI has the same struct as x86-64 */ -#define snd_timer_user_status_x32(file, s) \ - snd_timer_user_status(file, s) -#endif /* CONFIG_X86_X32 */ - -/* - */ - enum { SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32), SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32), - SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32), -#ifdef CONFIG_X86_X32 - SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status), -#endif /* CONFIG_X86_X32 */ + SNDRV_TIMER_IOCTL_STATUS_COMPAT32 = _IOW('T', 0x14, struct snd_timer_status32), + SNDRV_TIMER_IOCTL_STATUS_COMPAT64 = _IOW('T', 0x14, struct snd_timer_status64), }; static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, @@ -145,12 +102,10 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: return snd_timer_user_info_compat(file, argp); - case SNDRV_TIMER_IOCTL_STATUS32: - return snd_timer_user_status_compat(file, argp); -#ifdef CONFIG_X86_X32 - case SNDRV_TIMER_IOCTL_STATUS_X32: - return snd_timer_user_status_x32(file, argp); -#endif /* CONFIG_X86_X32 */ + case SNDRV_TIMER_IOCTL_STATUS_COMPAT32: + return snd_timer_user_status32(file, argp); + case SNDRV_TIMER_IOCTL_STATUS_COMPAT64: + return snd_timer_user_status64(file, argp); } return -ENOIOCTLCMD; } From patchwork Tue Nov 12 15:16:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179223 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8258809ilf; Tue, 12 Nov 2019 07:19:23 -0800 (PST) X-Google-Smtp-Source: APXvYqyBLMwn9Lqcqz0bJqy9413kunlIjm6a4UxG6sZ+fipokSqoIe4EcQDJOPO2FEekgJnepCOW X-Received: by 2002:a17:906:a457:: with SMTP id cb23mr28629963ejb.191.1573571963207; Tue, 12 Nov 2019 07:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571963; cv=none; d=google.com; s=arc-20160816; b=b+5TqYfyHqaemwdZJyDdCF/p9hJpw+F1i44+KsgxGD4+mFn4RFRfvqZARufq3pHL19 4wCQ9tZwgRUjUxezDpXPPrqTFhPDdqt+DQSWMqCrMQJdVBvbTVWgQ2bDdKzjOT5zcm9u rFzE+R2rWwrkEwxUjXE13NTO1vdtoh6oxMYGuTv5MVZ7Ggh4j6ZaST5xk91Uu61krv0J Mb9R/MKFjTyixzzMV0Wxn7ZzzOB7Pl2aTpIqZ4YCX+7XQyswTOtTQggJyi3sVMVKYBTd qVJRbMOhiyv7/hZXg+p6EUmZDcEcQVW9lWDzxVas2u6+0T4itThbacW4nOBteY64n6Qt u3PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xcVaA4hF5NRkiKDkA9rZZ7a/5XluI/AFb3vzoCgEbCU=; b=L6NQ1B2cQHvrSyZewpq4v7FeqDcuVkTLke4ws5FIu5oeCfzdswIqZ3cdzDPcjvDcld kXqmds2XqZQRbSOU7H4fJmOgyStvQlIzlnYjiUuWfWxofO1RniL2466SuA+ca0iz+T/Y yUcaFmgweuYkpvWPHekwgy0aTIKoyC6YscEnI15stLx6B9TENV002W6iGwVEEYY55NAk oelqQcE4xmdqtwwRpqn8q6Qle3TQt9ZS/ouY34uFX/XzeZsKd0wXyje6njRiJU5RupPV HsFVk8aRiaVbv1+UEHe0NunIuVL8qaKAj+UtjRtZGNGX0jcEhBPIZ4ZXnAJfDUxxu8b6 0N+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.19.17; Tue, 12 Nov 2019 07:19:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727492AbfKLPTN (ORCPT + 26 others); Tue, 12 Nov 2019 10:19:13 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:42673 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727392AbfKLPTA (ORCPT ); Tue, 12 Nov 2019 10:19:00 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MtfRp-1hc9qA0Y5H-00v4Hm; Tue, 12 Nov 2019 16:16:57 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 3/8] ALSA: Avoid using timespec for struct snd_ctl_elem_value Date: Tue, 12 Nov 2019 16:16:37 +0100 Message-Id: <20191112151642.680072-4-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:lAmj6kwQ3S1uoAqMviQM0k/X4NCJC4z7wsHW/iJ6hmK73azYUPt LeTeoMm+SHmEwAZSSGex8hmlIuQz1YByD4R8gEFDR4S+8G55DbnRcj0W0ApNMll1LTV74a0 eMmTSt5CgtWlHtvPZzJeGmfuKGcw5DNGmAbCUAJLXaT7Q1+DC17XLuD9xk4rBfumKtKNjGg 81fE5bja9OklrzP2MBUJw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:NBo0lQzLa3c=:TO19rw24nS3btXFzrd006z LH86aIw7gIdJ1DH9EzgtWisBKUxfHshRNwfm6je6GgCiQh1JWB17Ilq3e7N13lsbNAt5f3d41 YjJUYkVoQdvx9Z1iat/l5h/N9b2TjHp8v6NAm2LWn5cOqWHy1OeWIC2fGXA6PwwIdvdQd0392 oAZk2ix/wgG+bdCQKbQsrAmEw0VnpjUWOm+/Ia5YTRmIYvPgRUmS1fSIy50OvVWtuOS/xnIfe PVvEXxGKggyvU7VHTDWY3RfXIZ3lnAawDoi6eptSKIC+dF88FATHjsXCVF3+ZLVuDLmf4Oc7m wgl1j/bNO/22zESP/fxR0i8Xu6z7n80I6WL9+9x3UK3KpkTxAttrVOzPUe1WFD53MF9SqC2Pz Rf8dw6lAi0LzG/BkdXaHO9sumnOCpb5hDVUqj6sk3q/VS9WmS46RYghR3TJ8G05de7aiUa9wk AVlTOYNOAeUBVkwzrC9WM5cahcmMVXlNKV1vnakMfDZkGvCBwez09eOnVLKMA578el4yvpeFj CfIY3lrRaJ+z0bpEAoPEiHcCxBjV2ukhd9+Sqq7dbj/X+JVErMseRlb50e7cSNVPjjsUmGKvN i8rqbtgmSsPJP7HX/uvY8b6IzAuCxafnWmhT8xHDT2Wh5uTZN8xbyxjPRQXtNi/ZLzNY2o8Xc RxbvsLDLwyLlP/Ke/+3XeAep6/hUUMyCNPi4nDjauabkZGig4aOMT0We4ZkAwlO4KLfr9bncX d7W5sXZ1dnuh8dZi4yt3oHeDnZr5C52ECiVRTMOG+i8bA0Fv3s1t1/jDnsR6rUJY/mqQkEFUj jvpyaraqnBYUW/zQgOgJsxvhyv71jJ9P4IJJDAmkxZ4OKsoqYKPtYXEGJ2JUL7Sg7GoybdGh7 Ql4RYV1KciH+TmKXFnjg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang The struct snd_ctl_elem_value will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Since there are no drivers will implemented the tstamp member of the struct snd_ctl_elem_value, and also the stucture size will not be changed if we change timespec to s64 for tstamp member of struct snd_ctl_elem_value. >From Takashi's comments, "In the library, applications are not expected to access to this structure directly. The applications get opaque pointer to the structure and must use any control APIs to operate it. Actually the library produce no API to handle 'struct snd_ctl_elem_value.tstamp'. This means that we can drop this member from alsa-lib without decline of functionality." Thus we can simply remove the tstamp member to avoid using the type which is not year 2038 safe on 32bits system. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.20.0 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 930854f67fd3..40a23d8418fe 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -957,8 +957,7 @@ struct snd_ctl_elem_value { } bytes; struct snd_aes_iec958 iec958; } value; /* RO */ - struct timespec tstamp; - unsigned char reserved[128-sizeof(struct timespec)]; + unsigned char reserved[128]; }; struct snd_ctl_tlv { From patchwork Tue Nov 12 15:16:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179217 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8257841ilf; Tue, 12 Nov 2019 07:18:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz0LcnfnkrvSk9tlGnwhw/K9DjHIaWyPp/KtYP+NNN9rowgUHLfDTB54c8h+qU5kIx2163e X-Received: by 2002:a50:f296:: with SMTP id f22mr33351704edm.26.1573571919279; Tue, 12 Nov 2019 07:18:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571919; cv=none; d=google.com; s=arc-20160816; b=J25YZmJa1rhJQ5aiSnM9IX8KIGxOlkz8uIITUB/8NdP6xMzvtFhvm2wOBVpwM0y0x2 I5oqB91izz9BPdhJBuT7BVf/T+a6eizA5Bz1Qq7bMDvP93F++TG9B5xc3LC2cyuiyMMp sNDmIqPZf7NFIQymHiTHFB+ZoJInaf3enwjjQoU4TbK8LG5+6lARy7QAB2u+Nb8Z3KVT 4Wd58IxZV6rh74cDPIxwjcNKHMYQx0Z7tbAlEpXB09UyervVRU94ICZBNsjRvleOlsfX BqYnGph7A3NahXNyXTxdCXmK9F65KuiXmQ5V0YdORXAb60QRH8OZCJvsqv1JUOKQ8aCu JfrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cPXkYLVXO9PbKZCKwEriZhJXY5BVFjiusaMgZBtpAUc=; b=jyCkP/4/2OImey3jQLmV0TH5AHgndEPG2UpY98fH2YpnRuD2gqQIgddy4NCVpFfrYh 98JbXvTM60pHDN1Um6d/J3Lr4NfPJfM7SO9lXhcNPQqRTkFBSup6oign3iq9CzAcGFpo G2SJfGrlw67Gr4X3p3DIYxwirxYhNhOLVtZRgfhCqFX3Ezzd08trJqxXAZhqhZMt/SwU nGyPTeiTxC6Vc97SZ3iiq26473/k7eotceDvu/YbFSs3htbKM1tgCBjgcn+fu7MhFeTH jDeb/iPK8j2CIhay7YkzivFvwpc3bVkpdhOh00D4Ly3lDBL/9ZGT5GsyApkz4NMJiUyj akkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.34; Tue, 12 Nov 2019 07:18:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfKLPS0 (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:26 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:53285 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727046AbfKLPSZ (ORCPT ); Tue, 12 Nov 2019 10:18:25 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MLz3X-1iD9cO1qlN-00HseO; Tue, 12 Nov 2019 16:16:57 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 4/8] ALSA: Avoid using timespec for struct snd_pcm_status Date: Tue, 12 Nov 2019 16:16:38 +0100 Message-Id: <20191112151642.680072-5-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9eI6Hrt6cjo4B+mCObWL9Eo1+tPItSec9OZ0/THgJC8FlB3LBMY +Z2+tVqtnmwc+lOxcsa9oSULf1Gao/qqMeCKRgM//Ew9Jam9HXbZ5+Nc5M6RCh2+MO1OvxV Kn26YiIDneeaZJ7Po6baJqbEqi2PHlO/RlGfGv2Rz0dxQi/WUrgxZmPJ13RF5eFljK9ChFr oho/YOX9XW5MRvgJqyr1w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:BOEmO2h/jzg=:N8Z4ufRHwvUBXGAL33FQvi HNuLpSV2Zy4CeDQKvivnRhPbg9T7USh3YBBu1AJxY/Jnrsgf5ZizqWdrrpCMe20+QbbhVzwKI 61NJdZlouXrOsU5eci2z/nUSkrKrZ46xckl8UIYNnmm8c8QyVwHA4nCeso30ALL2D/oPNDY1s IOWr8ji0wI6waWv54cBK3HYDc05jcvLe6yGsgQYauEPgrVttd2aH7oYAUKmlHzKrve0KP1P27 sHVWYCBkjb5X/tz6tQWUvHqxqOpoxrOv+Z2qh051SYn0zYrIqooE4z6UyN5SeL+XnjzjbD9Le WTr8vycSNlzhELNfyVaqdmK58n9J449t5z9le6Km+6nmXDkf/hGTK9M5ZqmxrI6hp+QNvCe5r F1m1UpEGl/C9d5lSBBswnkQEnMrw/B3a8ZwKGL//n/Sve6nsNTCFoFpz34Pf9/J5H1LSU+rUe dapySRD6YzEfQDWoKQYOXHxNxQwBw1SgjRkY2c987j7EYm3UHr521rS/cLc1U2RIUMu+DVN84 deQH4ArDI+eOBnoq9K5m1mNvf9uqXg+FE33H8X8H2TopTZbdBfQh5M1s9MllMa9pubDsioFix u/hxRU4VJnfeRxINaV2FaexCcZugYhzOXb2AetsH3POl2pZdRxr87IQshtSCYj0sZO6TSHqX1 WaZf1L0HlpXz4ykTj9klggnnwlsoZlTBkEKq5jAH/3QoWNpPMhycgLxZf5nuBfs5FQQ6BgJIl 5OoeqbXf7FqTvNA95oYhulJJvKibO4wTfhDIAQ4Ys1uRnmA7IcJwZ8C2mVSlC2cRPcQSDzwOK fZISGubqD3LeVS2PdoL0+2CWP+rYsBL8I2w4yRkQ6bfZ0t7hJ0Hq9eFJTZrFkd9ubk2XNSsmK uSg451z0VY0nPq2CNbWg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang The struct snd_pcm_status will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Userspace will use SNDRV_PCM_IOCTL_STATUS and SNDRV_PCM_IOCTL_STATUS_EXT as commands to issue ioctl() to fill the 'snd_pcm_status' structure in userspace. The command number is always defined through _IOR/_IOW/IORW, so when userspace changes the definition of 'struct timespec' to use 64-bit types, the command number also changes. Thus in the kernel, we now need to define two versions of each such ioctl and corresponding ioctl commands to handle 32bit time_t and 64bit time_t in native mode: struct snd_pcm_status32 { ...... s32 trigger_tstamp_sec; s32 trigger_tstamp_nsec; ...... s32 audio_tstamp_sec; s32 audio_tstamp_nsec; ...... }; struct snd_pcm_status64 { ...... s32 trigger_tstamp_sec; s32 trigger_tstamp_nsec; ...... s32 audio_tstamp_sec; s32 audio_tstamp_nsec; ...... }; Moreover in compat file, we renamed or introduced new structures to handle 32bit/64bit time_t in compatible mode. The 'struct snd_pcm_status32' and snd_pcm_status_user32() are used to handle 32bit time_t in compat mode. 'struct compat_snd_pcm_status64' and snd_pcm_status_user_compat64() are used to handle 64bit time_t. Finally we can replace SNDRV_PCM_IOCTL_STATUS and SNDRV_PCM_IOCTL_STATUS_EXT with new commands and introduce new functions to fill new 'struct snd_pcm_status64' instead of using unsafe 'struct snd_pcm_status'. Then in future, the new commands can be matched when userspace changes 'timespec' to 64bit type to make a size change of 'struct snd_pcm_status'. When glibc changes time_t to 64-bit, any recompiled program will issue ioctl commands that the kernel does not understand without this patch. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/sound/pcm.h | 56 ++++++++++++- include/uapi/sound/asound.h | 3 + sound/core/pcm.c | 12 +-- sound/core/pcm_compat.c | 154 +++++++++++++----------------------- sound/core/pcm_native.c | 96 ++++++++++++++++++---- 5 files changed, 195 insertions(+), 126 deletions(-) -- 2.20.0 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2665b3dc15e8..3366128f42a2 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -44,6 +44,7 @@ struct snd_pcm_hardware { size_t fifo_size; /* fifo size in bytes */ }; +struct snd_pcm_status64; struct snd_pcm_substream; struct snd_pcm_audio_tstamp_config; /* definitions further down */ @@ -554,8 +555,8 @@ int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree); int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info); int snd_pcm_info_user(struct snd_pcm_substream *substream, struct snd_pcm_info __user *info); -int snd_pcm_status(struct snd_pcm_substream *substream, - struct snd_pcm_status *status); +int snd_pcm_status64(struct snd_pcm_substream *substream, + struct snd_pcm_status64 *status); int snd_pcm_start(struct snd_pcm_substream *substream); int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status); int snd_pcm_drain_done(struct snd_pcm_substream *substream); @@ -1422,4 +1423,55 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format) #define pcm_dbg(pcm, fmt, args...) \ dev_dbg((pcm)->card->dev, fmt, ##args) +struct snd_pcm_status64 { + snd_pcm_state_t state; /* stream state */ + u8 rsvd[4]; + s64 trigger_tstamp_sec; /* time when stream was started/stopped/paused */ + s64 trigger_tstamp_nsec; + s64 tstamp_sec; /* reference timestamp */ + s64 tstamp_nsec; + snd_pcm_uframes_t appl_ptr; /* appl ptr */ + snd_pcm_uframes_t hw_ptr; /* hw ptr */ + snd_pcm_sframes_t delay; /* current delay in frames */ + snd_pcm_uframes_t avail; /* number of frames available */ + snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */ + snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ + snd_pcm_state_t suspended_state; /* suspended stream state */ + __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ + s64 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */ + s64 audio_tstamp_nsec; + s64 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */ + s64 driver_tstamp_nsec; + __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ + unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */ +}; + +#define SNDRV_PCM_IOCTL_STATUS64 _IOR('A', 0x20, struct snd_pcm_status64) +#define SNDRV_PCM_IOCTL_STATUS_EXT64 _IOWR('A', 0x24, struct snd_pcm_status64) + +struct snd_pcm_status32 { + s32 state; /* stream state */ + s32 trigger_tstamp_sec; /* time when stream was started/stopped/paused */ + s32 trigger_tstamp_nsec; + s32 tstamp_sec; /* reference timestamp */ + s32 tstamp_nsec; + u32 appl_ptr; /* appl ptr */ + u32 hw_ptr; /* hw ptr */ + s32 delay; /* current delay in frames */ + u32 avail; /* number of frames available */ + u32 avail_max; /* max frames available on hw since last status */ + u32 overrange; /* count of ADC (capture) overrange detections from last status */ + s32 suspended_state; /* suspended stream state */ + u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ + s32 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */ + s32 audio_tstamp_nsec; + s32 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */ + s32 driver_tstamp_nsec; + u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ + unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */ +}; + +#define SNDRV_PCM_IOCTL_STATUS32 _IOR('A', 0x20, struct snd_pcm_status32) +#define SNDRV_PCM_IOCTL_STATUS_EXT32 _IOWR('A', 0x24, struct snd_pcm_status32) + #endif /* __SOUND_PCM_H */ diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 40a23d8418fe..7b74524f9406 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -456,8 +456,10 @@ enum { SNDRV_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED }; +#ifndef __KERNEL__ struct snd_pcm_status { snd_pcm_state_t state; /* stream state */ + unsigned char pad1[sizeof(time_t) - sizeof(snd_pcm_state_t)]; /* align to timespec */ struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ struct timespec tstamp; /* reference timestamp */ snd_pcm_uframes_t appl_ptr; /* appl ptr */ @@ -473,6 +475,7 @@ struct snd_pcm_status { __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */ }; +#endif struct snd_pcm_mmap_status { snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 9a72d641743d..85db55ea49fd 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -443,7 +443,7 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, { struct snd_pcm_substream *substream = entry->private_data; struct snd_pcm_runtime *runtime; - struct snd_pcm_status status; + struct snd_pcm_status64 status; int err; mutex_lock(&substream->pcm->open_mutex); @@ -453,17 +453,17 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, goto unlock; } memset(&status, 0, sizeof(status)); - err = snd_pcm_status(substream, &status); + err = snd_pcm_status64(substream, &status); if (err < 0) { snd_iprintf(buffer, "error %d\n", err); goto unlock; } snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state)); snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid)); - snd_iprintf(buffer, "trigger_time: %ld.%09ld\n", - status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec); - snd_iprintf(buffer, "tstamp : %ld.%09ld\n", - status.tstamp.tv_sec, status.tstamp.tv_nsec); + snd_iprintf(buffer, "trigger_time: %lld.%09lld\n", + status.trigger_tstamp_sec, status.trigger_tstamp_nsec); + snd_iprintf(buffer, "tstamp : %lld.%09lld\n", + status.tstamp_sec, status.tstamp_nsec); snd_iprintf(buffer, "delay : %ld\n", status.delay); snd_iprintf(buffer, "avail : %ld\n", status.avail); snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max); diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index 6f9003b1869a..2671658442ea 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -168,73 +168,13 @@ static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, snd_pcm_channel_info_user(s, p) #endif /* CONFIG_X86_X32 */ -struct snd_pcm_status32 { +struct compat_snd_pcm_status64 { s32 state; - struct compat_timespec trigger_tstamp; - struct compat_timespec tstamp; - u32 appl_ptr; - u32 hw_ptr; - s32 delay; - u32 avail; - u32 avail_max; - u32 overrange; - s32 suspended_state; - u32 audio_tstamp_data; - struct compat_timespec audio_tstamp; - struct compat_timespec driver_tstamp; - u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct compat_timespec)]; -} __attribute__((packed)); - - -static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, - struct snd_pcm_status32 __user *src, - bool ext) -{ - struct snd_pcm_status status; - int err; - - memset(&status, 0, sizeof(status)); - /* - * with extension, parameters are read/write, - * get audio_tstamp_data from user, - * ignore rest of status structure - */ - if (ext && get_user(status.audio_tstamp_data, - (u32 __user *)(&src->audio_tstamp_data))) - return -EFAULT; - err = snd_pcm_status(substream, &status); - if (err < 0) - return err; - - if (clear_user(src, sizeof(*src))) - return -EFAULT; - if (put_user(status.state, &src->state) || - compat_put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - compat_put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.appl_ptr, &src->appl_ptr) || - put_user(status.hw_ptr, &src->hw_ptr) || - put_user(status.delay, &src->delay) || - put_user(status.avail, &src->avail) || - put_user(status.avail_max, &src->avail_max) || - put_user(status.overrange, &src->overrange) || - put_user(status.suspended_state, &src->suspended_state) || - put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) || - put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) - return -EFAULT; - - return err; -} - -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_pcm_status_x32 { - s32 state; - u32 rsvd; /* alignment */ - struct timespec trigger_tstamp; - struct timespec tstamp; + u8 rsvd[4]; /* alignment */ + s64 trigger_tstamp_sec; + s64 trigger_tstamp_nsec; + s64 tstamp_sec; + s64 tstamp_nsec; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -243,22 +183,26 @@ struct snd_pcm_status_x32 { u32 overrange; s32 suspended_state; u32 audio_tstamp_data; - struct timespec audio_tstamp; - struct timespec driver_tstamp; + s64 audio_tstamp_sec; + s64 audio_tstamp_nsec; + s64 driver_tstamp_sec; + s64 driver_tstamp_nsec; u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct timespec)]; + unsigned char reserved[52-4*sizeof(s64)]; } __packed; #define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst)) -static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, - struct snd_pcm_status_x32 __user *src, - bool ext) +static int snd_pcm_status_user_compat64(struct snd_pcm_substream *substream, + struct compat_snd_pcm_status64 __user *src, + bool ext) { - struct snd_pcm_status status; + struct snd_pcm_status64 status; + struct compat_snd_pcm_status64 compat_status64; int err; memset(&status, 0, sizeof(status)); + memset(&compat_status64, 0, sizeof(compat_status64)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, @@ -267,31 +211,39 @@ static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&src->audio_tstamp_data))) return -EFAULT; - err = snd_pcm_status(substream, &status); + err = snd_pcm_status64(substream, &status); if (err < 0) return err; if (clear_user(src, sizeof(*src))) return -EFAULT; - if (put_user(status.state, &src->state) || - put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.appl_ptr, &src->appl_ptr) || - put_user(status.hw_ptr, &src->hw_ptr) || - put_user(status.delay, &src->delay) || - put_user(status.avail, &src->avail) || - put_user(status.avail_max, &src->avail_max) || - put_user(status.overrange, &src->overrange) || - put_user(status.suspended_state, &src->suspended_state) || - put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - put_timespec(&status.driver_tstamp, &src->driver_tstamp) || - put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) + + compat_status64 = (struct compat_snd_pcm_status64) { + .state = status.state, + .trigger_tstamp_sec = status.trigger_tstamp_sec, + .trigger_tstamp_nsec = status.trigger_tstamp_nsec, + .tstamp_sec = status.tstamp_sec, + .tstamp_nsec = status.tstamp_nsec, + .appl_ptr = status.appl_ptr, + .hw_ptr = status.hw_ptr, + .delay = status.delay, + .avail = status.avail, + .avail_max = status.avail_max, + .overrange = status.overrange, + .suspended_state = status.suspended_state, + .audio_tstamp_data = status.audio_tstamp_data, + .audio_tstamp_sec = status.audio_tstamp_sec, + .audio_tstamp_nsec = status.audio_tstamp_nsec, + .driver_tstamp_sec = status.audio_tstamp_sec, + .driver_tstamp_nsec = status.audio_tstamp_nsec, + .audio_tstamp_accuracy = status.audio_tstamp_accuracy, + }; + + if (copy_to_user(src, &compat_status64, sizeof(compat_status64))) return -EFAULT; return err; } -#endif /* CONFIG_X86_X32 */ /* both for HW_PARAMS and HW_REFINE */ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream, @@ -616,8 +568,8 @@ enum { SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32), - SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32), - SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32), + SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32), SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32), SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32), SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32), @@ -627,10 +579,10 @@ enum { SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32), SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32), SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), + SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64), #ifdef CONFIG_X86_X32 SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info), - SNDRV_PCM_IOCTL_STATUS_X32 = _IOR('A', 0x20, struct snd_pcm_status_x32), - SNDRV_PCM_IOCTL_STATUS_EXT_X32 = _IOWR('A', 0x24, struct snd_pcm_status_x32), SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32), #endif /* CONFIG_X86_X32 */ }; @@ -680,10 +632,10 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_ioctl_hw_params_compat(substream, 0, argp); case SNDRV_PCM_IOCTL_SW_PARAMS32: return snd_pcm_ioctl_sw_params_compat(substream, argp); - case SNDRV_PCM_IOCTL_STATUS32: - return snd_pcm_status_user_compat(substream, argp, false); - case SNDRV_PCM_IOCTL_STATUS_EXT32: - return snd_pcm_status_user_compat(substream, argp, true); + case SNDRV_PCM_IOCTL_STATUS_COMPAT32: + return snd_pcm_status_user32(substream, argp, false); + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: + return snd_pcm_status_user32(substream, argp, true); case SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_ioctl_sync_ptr_compat(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: @@ -702,11 +654,11 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_ioctl_rewind_compat(substream, argp); case SNDRV_PCM_IOCTL_FORWARD32: return snd_pcm_ioctl_forward_compat(substream, argp); + case SNDRV_PCM_IOCTL_STATUS_COMPAT64: + return snd_pcm_status_user_compat64(substream, argp, false); + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64: + return snd_pcm_status_user_compat64(substream, argp, true); #ifdef CONFIG_X86_X32 - case SNDRV_PCM_IOCTL_STATUS_X32: - return snd_pcm_status_user_x32(substream, argp, false); - case SNDRV_PCM_IOCTL_STATUS_EXT_X32: - return snd_pcm_status_user_x32(substream, argp, true); case SNDRV_PCM_IOCTL_SYNC_PTR_X32: return snd_pcm_ioctl_sync_ptr_x32(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32: diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 7d0fe30f1658..2c8c9b91677a 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -852,8 +852,8 @@ snd_pcm_calc_delay(struct snd_pcm_substream *substream) return delay + substream->runtime->delay; } -int snd_pcm_status(struct snd_pcm_substream *substream, - struct snd_pcm_status *status) +int snd_pcm_status64(struct snd_pcm_substream *substream, + struct snd_pcm_status64 *status) { struct snd_pcm_runtime *runtime = substream->runtime; @@ -879,14 +879,22 @@ int snd_pcm_status(struct snd_pcm_substream *substream, status->suspended_state = runtime->status->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; - status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp); + status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; + status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { - status->tstamp = runtime->status->tstamp; - status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp); - status->audio_tstamp = - runtime->status->audio_tstamp; + status->tstamp_sec = runtime->status->tstamp.tv_sec; + status->tstamp_nsec = + runtime->status->tstamp.tv_nsec; + status->driver_tstamp_sec = + runtime->driver_tstamp.tv_sec; + status->driver_tstamp_nsec = + runtime->driver_tstamp.tv_nsec; + status->audio_tstamp_sec = + runtime->status->audio_tstamp.tv_sec; + status->audio_tstamp_nsec = + runtime->status->audio_tstamp.tv_nsec; if (runtime->audio_tstamp_report.valid == 1) /* backwards compatibility, no report provided in COMPAT mode */ snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data, @@ -901,7 +909,8 @@ int snd_pcm_status(struct snd_pcm_substream *substream, struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); - status->tstamp = timespec64_to_timespec(tstamp); + status->tstamp_sec = tstamp.tv_sec; + status->tstamp_nsec = tstamp.tv_nsec; } } _tstamp_end: @@ -919,11 +928,11 @@ int snd_pcm_status(struct snd_pcm_substream *substream, return 0; } -static int snd_pcm_status_user(struct snd_pcm_substream *substream, - struct snd_pcm_status __user * _status, - bool ext) +static int snd_pcm_status_user64(struct snd_pcm_substream *substream, + struct snd_pcm_status64 __user * _status, + bool ext) { - struct snd_pcm_status status; + struct snd_pcm_status64 status; int res; memset(&status, 0, sizeof(status)); @@ -935,7 +944,7 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream, if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&_status->audio_tstamp_data))) return -EFAULT; - res = snd_pcm_status(substream, &status); + res = snd_pcm_status64(substream, &status); if (res < 0) return res; if (copy_to_user(_status, &status, sizeof(status))) @@ -943,6 +952,55 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream, return 0; } +static int snd_pcm_status_user32(struct snd_pcm_substream *substream, + struct snd_pcm_status32 __user * _status, + bool ext) +{ + struct snd_pcm_status64 status64; + struct snd_pcm_status32 status32; + int res; + + memset(&status64, 0, sizeof(status64)); + memset(&status32, 0, sizeof(status32)); + /* + * with extension, parameters are read/write, + * get audio_tstamp_data from user, + * ignore rest of status structure + */ + if (ext && get_user(status64.audio_tstamp_data, + (u32 __user *)(&_status->audio_tstamp_data))) + return -EFAULT; + res = snd_pcm_status64(substream, &status64); + if (res < 0) + return res; + + status32 = (struct snd_pcm_status32) { + .state = status64.state, + .trigger_tstamp_sec = status64.trigger_tstamp_sec, + .trigger_tstamp_nsec = status64.trigger_tstamp_nsec, + .tstamp_sec = status64.tstamp_sec, + .tstamp_nsec = status64.tstamp_nsec, + .appl_ptr = status64.appl_ptr, + .hw_ptr = status64.hw_ptr, + .delay = status64.delay, + .avail = status64.avail, + .avail_max = status64.avail_max, + .overrange = status64.overrange, + .suspended_state = status64.suspended_state, + .audio_tstamp_data = status64.audio_tstamp_data, + .audio_tstamp_sec = status64.audio_tstamp_sec, + .audio_tstamp_nsec = status64.audio_tstamp_nsec, + .driver_tstamp_sec = status64.audio_tstamp_sec, + .driver_tstamp_nsec = status64.audio_tstamp_nsec, + .audio_tstamp_accuracy = status64.audio_tstamp_accuracy, + }; + + if (copy_to_user(_status, &status32, sizeof(status32))) + return -EFAULT; + + return 0; +} + static int snd_pcm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info * info) { @@ -2917,10 +2975,14 @@ static int snd_pcm_common_ioctl(struct file *file, return snd_pcm_hw_free(substream); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params_user(substream, arg); - case SNDRV_PCM_IOCTL_STATUS: - return snd_pcm_status_user(substream, arg, false); - case SNDRV_PCM_IOCTL_STATUS_EXT: - return snd_pcm_status_user(substream, arg, true); + case SNDRV_PCM_IOCTL_STATUS32: + return snd_pcm_status_user32(substream, arg, false); + case SNDRV_PCM_IOCTL_STATUS_EXT32: + return snd_pcm_status_user32(substream, arg, true); + case SNDRV_PCM_IOCTL_STATUS64: + return snd_pcm_status_user64(substream, arg, false); + case SNDRV_PCM_IOCTL_STATUS_EXT64: + return snd_pcm_status_user64(substream, arg, true); case SNDRV_PCM_IOCTL_CHANNEL_INFO: return snd_pcm_channel_info_user(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: From patchwork Tue Nov 12 15:16:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179216 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8257740ilf; Tue, 12 Nov 2019 07:18:34 -0800 (PST) X-Google-Smtp-Source: APXvYqxnIDK4tyijDKejGxmZgzpBiIboqa46NfD/uZyZXJYn+CK24I/DLpLzIE+NSvj+Z94K7/Fz X-Received: by 2002:a17:907:2122:: with SMTP id qo2mr29326935ejb.12.1573571914636; Tue, 12 Nov 2019 07:18:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571914; cv=none; d=google.com; s=arc-20160816; b=wySa3BeTEkFhT6ZP+kT1koYQDfjqcyI0R3ZBRZbcDQg4gI3BFg8M0SgWhJ1j4iIsFe 5EOlL2ZM2+1hNNV8JdKBbOz6AEZBsWjeSYSvmkcuko+bZRp8SyLsik4AXyNpAWz2iUcq bHpDwCfvdRITosxDlRATebkS1PV0S6zI7VasDZB7mWHRCOYZ3im/0Vmz1qH4vrYz+rOl b/quWhtjW+0KkMurhZ2Wf2atvlBbpl3Bg5HfXkDZx7dkuSP8dYv8mlKqUpBmCT0OQeq6 CHkiePZn//oXHYtCrwCb7n9Zs8lh2ZstfuyMvZeKFlv/GHnM2lzucVjxa3CZp0UKneKj M1jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ime77aPyto+IIzB5hbmMDp1UaO1QrNbP0MrHfQTggPk=; b=JTgsDq2sCwwIWvQkOSE9q9inG/srbWhs8E2EASHtHLoOAsTV5El5R6gpkleprWesjx ge7+2q09MPr7XOUjq080fBBN6YkEYrHCkFh+9x/JDKHZH3MbPAVoRitMocdm8OaSQDrb drXZch573XVtFSYQhcBmskHBmdmGJ2V7/dUCGNqqB9rqSU/vQ8YT0qZ4FrmDbqFG7bsM /rEiOvBtbJihwjcUusxJE9ag4AIKs/69xTHTnp89gcTdr8vv75nXamov/kDxvYzQzdE7 89nZcVud+Il5dwLgbFYIp4JhmlS2vDWCBzOBIHiVhVyt7Vf4hUpKbst1QRi1goKeYj1d 8BGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.30; Tue, 12 Nov 2019 07:18:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727211AbfKLPSZ (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:25 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:44323 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbfKLPSX (ORCPT ); Tue, 12 Nov 2019 10:18:23 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MxDgs-1hfkbx37SC-00xZ7R; Tue, 12 Nov 2019 16:16:57 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 5/8] ALSA: Avoid using timespec for struct snd_rawmidi_status Date: Tue, 12 Nov 2019 16:16:39 +0100 Message-Id: <20191112151642.680072-6-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:oteOMmI0dXPrDHNc2XCfhWBTdBAsQTVsR3zs+QycZH8TUXTIfxR umwN0s0jIaMu6jGbAPZgimTu9AqcoxYPCDBhSFXdE/Xd7/7owaQ8yM65DCZPch15xJ6Ad4U /nTZBdUK44nL+r+u1Q8GDlOsnrz5B+UdGw1ct5PCU5gnptsOtYSV81pYVLMep7B/Dudvx/2 FgNMh0DCOsYjDwBndsi5w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:Dln6VzD+Ggo=:leyUFR3GRK8xNY7NyYzdvk L2ct6UfBSUnYUR28nfSqY3Wu5JdSUEz0pJnGIgPAIGiotK67rePTS3C4UUs2+TRpoh1+Bif/N C0eX9DM9/ZmoSuSLfbgtLDuiezKKB8r7sTEZKtsoSr12d4eRlj74+rJRwGUgoX37CQ7+nb4ui PSqrlR0EW/unHh/J2iX0nY1+NsWPs1ckqbK9P9SEnWF2IQYT5wexpyCXZuWDS8oEcUqSQT2AI Dsru1WzjdhyTepH0Vh1Ij5SC9TZ8ijwEGg1+Bms+BSJKzXpOFAvuwl9BZYU/5YHriYepVwon2 P9dghNI5HWuzEFqmjb6XQ7kbQzi7aP4BSThPjjL5vGw4AFEyJ0+JOxzbFjZJZWoURS7Hv5+DD 7RWcwok7JjMY9QumGTifXqPbfiEF1uVWn2DTfNXr5iAWxM0jyJEM9edu+Jcd4+kQBP+tJwwLK icW4ANHXerhLP3foqjKENIn9F0OZNyiXDBFhYo0nyi8XG9TSlqDF+7WwAKBrMRhIao3VK0B0X tHmdfl689MFpP+pDUEV0n68si28RT3AMk6WL4rqlCkWzjncQBbpfdY267JuPReF4+0yJMTP+D /v9SAW//LhpPG9ZIQCelr51uZ+clQFil5BKYZUTFwEF3bXyz/DMDvgXsz7BVn04ACvD5x7M40 r+zvvRFWmpqrK1BSbGKMtanOmHXkYhQMb4zw4/hNsNA/lYyMATGh51gfjDLxMC/WzENqiMfhI l/e/GkmrS3L3jE4A5rErmHMucaVK6eCN0tWBXV1o3qmenkioSNgz+ZWoRXY4nzeyqXTVvj/B6 vdGBJ65Uc1zhz/XJWpG4UYv+ozcWtzhB9glNfax84pkDaEG9bXNr/Brtb5BEnrscgCqg0Ai4I +qgrthNLvakP5HQTN+2Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang The struct snd_rawmidi_status will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Thus we introduced 'struct snd_rawmidi_status32' and 'struct snd_rawmidi_status64' to handle 32bit time_t and 64bit time_t in native mode, which replace timespec with s64 type. In compat mode, we renamed or introduced new structures to handle 32bit/64bit time_t in compatible mode. The 'struct snd_rawmidi_status32' and snd_rawmidi_ioctl_status32() are used to handle 32bit time_t in compat mode. 'struct compat_snd_rawmidi_status64' is used to handle 64bit time_t. When glibc changes time_t to 64-bit, any recompiled program will issue ioctl commands that the kernel does not understand without this patch. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 3 + sound/core/rawmidi.c | 132 ++++++++++++++++++++++++++++-------- sound/core/rawmidi_compat.c | 87 ++++++------------------ 3 files changed, 128 insertions(+), 94 deletions(-) -- 2.20.0 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 7b74524f9406..cb830813da5d 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -651,13 +651,16 @@ struct snd_rawmidi_params { unsigned char reserved[16]; /* reserved for future use */ }; +#ifndef __KERNEL__ struct snd_rawmidi_status { int stream; + unsigned char pad1[sizeof(time_t) - sizeof(int)]; struct timespec tstamp; /* Timestamp */ size_t avail; /* available bytes */ size_t xruns; /* count of overruns since last status (in bytes) */ unsigned char reserved[16]; /* reserved for future use */ }; +#endif #define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int) #define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info) diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index 8a12a7538d63..cd9bbb546846 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -50,6 +50,29 @@ static DEFINE_MUTEX(register_mutex); #define rmidi_dbg(rmidi, fmt, args...) \ dev_dbg(&(rmidi)->dev, fmt, ##args) +struct snd_rawmidi_status32 { + s32 stream; + s32 tstamp_sec; /* Timestamp */ + s32 tstamp_nsec; + u32 avail; /* available bytes */ + u32 xruns; /* count of overruns since last status (in bytes) */ + unsigned char reserved[16]; /* reserved for future use */ +}; + +#define SNDRV_RAWMIDI_IOCTL_STATUS32 _IOWR('W', 0x20, struct snd_rawmidi_status32) + +struct snd_rawmidi_status64 { + int stream; + u8 rsvd[4]; /* alignment */ + s64 tstamp_sec; /* Timestamp */ + s64 tstamp_nsec; + size_t avail; /* available bytes */ + size_t xruns; /* count of overruns since last status (in bytes) */ + unsigned char reserved[16]; /* reserved for future use */ +}; + +#define SNDRV_RAWMIDI_IOCTL_STATUS64 _IOWR('W', 0x20, struct snd_rawmidi_status64) + static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device) { struct snd_rawmidi *rawmidi; @@ -677,7 +700,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, EXPORT_SYMBOL(snd_rawmidi_input_params); static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream, - struct snd_rawmidi_status *status) + struct snd_rawmidi_status64 *status) { struct snd_rawmidi_runtime *runtime = substream->runtime; @@ -690,7 +713,7 @@ static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream, } static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream, - struct snd_rawmidi_status *status) + struct snd_rawmidi_status64 *status) { struct snd_rawmidi_runtime *runtime = substream->runtime; @@ -704,6 +727,80 @@ static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream, return 0; } +static int snd_rawmidi_ioctl_status32(struct snd_rawmidi_file *rfile, + struct snd_rawmidi_status32 __user *argp) +{ + int err = 0; + struct snd_rawmidi_status32 __user *status = argp; + struct snd_rawmidi_status32 status32; + struct snd_rawmidi_status64 status64; + + if (copy_from_user(&status32, argp, + sizeof(struct snd_rawmidi_status32))) + return -EFAULT; + + switch (status32.stream) { + case SNDRV_RAWMIDI_STREAM_OUTPUT: + if (rfile->output == NULL) + return -EINVAL; + err = snd_rawmidi_output_status(rfile->output, &status64); + break; + case SNDRV_RAWMIDI_STREAM_INPUT: + if (rfile->input == NULL) + return -EINVAL; + err = snd_rawmidi_input_status(rfile->input, &status64); + break; + default: + return -EINVAL; + } + if (err < 0) + return err; + + status32 = (struct snd_rawmidi_status32) { + .stream = status64.stream, + .tstamp_sec = status64.tstamp_sec, + .tstamp_nsec = status64.tstamp_nsec, + .avail = status64.avail, + .xruns = status64.xruns, + }; + + if (copy_to_user(status, &status32, sizeof(*status))) + return -EFAULT; + + return 0; +} + +static int snd_rawmidi_ioctl_status64(struct snd_rawmidi_file *rfile, + struct snd_rawmidi_status64 __user *argp) +{ + int err = 0; + struct snd_rawmidi_status64 status; + + if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status64))) + return -EFAULT; + + switch (status.stream) { + case SNDRV_RAWMIDI_STREAM_OUTPUT: + if (rfile->output == NULL) + return -EINVAL; + err = snd_rawmidi_output_status(rfile->output, &status); + break; + case SNDRV_RAWMIDI_STREAM_INPUT: + if (rfile->input == NULL) + return -EINVAL; + err = snd_rawmidi_input_status(rfile->input, &status); + break; + default: + return -EINVAL; + } + if (err < 0) + return err; + if (copy_to_user(argp, &status, + sizeof(struct snd_rawmidi_status64))) + return -EFAULT; + return 0; +} + static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_rawmidi_file *rfile; @@ -750,33 +847,10 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long return -EINVAL; } } - case SNDRV_RAWMIDI_IOCTL_STATUS: - { - int err = 0; - struct snd_rawmidi_status status; - - if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status))) - return -EFAULT; - switch (status.stream) { - case SNDRV_RAWMIDI_STREAM_OUTPUT: - if (rfile->output == NULL) - return -EINVAL; - err = snd_rawmidi_output_status(rfile->output, &status); - break; - case SNDRV_RAWMIDI_STREAM_INPUT: - if (rfile->input == NULL) - return -EINVAL; - err = snd_rawmidi_input_status(rfile->input, &status); - break; - default: - return -EINVAL; - } - if (err < 0) - return err; - if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status))) - return -EFAULT; - return 0; - } + case SNDRV_RAWMIDI_IOCTL_STATUS32: + return snd_rawmidi_ioctl_status32(rfile, argp); + case SNDRV_RAWMIDI_IOCTL_STATUS64: + return snd_rawmidi_ioctl_status64(rfile, argp); case SNDRV_RAWMIDI_IOCTL_DROP: { int val; diff --git a/sound/core/rawmidi_compat.c b/sound/core/rawmidi_compat.c index 66eee61674b6..7397130976d0 100644 --- a/sound/core/rawmidi_compat.c +++ b/sound/core/rawmidi_compat.c @@ -41,19 +41,22 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, return -EINVAL; } -struct snd_rawmidi_status32 { +struct compat_snd_rawmidi_status64 { s32 stream; - struct compat_timespec tstamp; + u8 rsvd[4]; /* alignment */ + s64 tstamp_sec; + s64 tstamp_nsec; u32 avail; u32 xruns; unsigned char reserved[16]; } __attribute__((packed)); -static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile, - struct snd_rawmidi_status32 __user *src) +static int snd_rawmidi_ioctl_status_compat64(struct snd_rawmidi_file *rfile, + struct compat_snd_rawmidi_status64 __user *src) { int err; - struct snd_rawmidi_status status; + struct snd_rawmidi_status64 status; + struct compat_snd_rawmidi_status64 compat_status; if (get_user(status.stream, &src->stream)) return -EFAULT; @@ -75,68 +78,24 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile, if (err < 0) return err; - if (compat_put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.avail, &src->avail) || - put_user(status.xruns, &src->xruns)) - return -EFAULT; - - return 0; -} - -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_rawmidi_status_x32 { - s32 stream; - u32 rsvd; /* alignment */ - struct timespec tstamp; - u32 avail; - u32 xruns; - unsigned char reserved[16]; -} __attribute__((packed)); - -#define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst)) - -static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, - struct snd_rawmidi_status_x32 __user *src) -{ - int err; - struct snd_rawmidi_status status; - - if (get_user(status.stream, &src->stream)) - return -EFAULT; - - switch (status.stream) { - case SNDRV_RAWMIDI_STREAM_OUTPUT: - if (!rfile->output) - return -EINVAL; - err = snd_rawmidi_output_status(rfile->output, &status); - break; - case SNDRV_RAWMIDI_STREAM_INPUT: - if (!rfile->input) - return -EINVAL; - err = snd_rawmidi_input_status(rfile->input, &status); - break; - default: - return -EINVAL; - } - if (err < 0) - return err; + compat_status = (struct compat_snd_rawmidi_status64) { + .stream = status.stream, + .tstamp_sec = status.tstamp_sec, + .tstamp_nsec = status.tstamp_nsec, + .avail = status.avail, + .xruns = status.xruns, + }; - if (put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.avail, &src->avail) || - put_user(status.xruns, &src->xruns)) + if (copy_to_user(src, &compat_status, sizeof(*src))) return -EFAULT; return 0; } -#endif /* CONFIG_X86_X32 */ enum { SNDRV_RAWMIDI_IOCTL_PARAMS32 = _IOWR('W', 0x10, struct snd_rawmidi_params32), - SNDRV_RAWMIDI_IOCTL_STATUS32 = _IOWR('W', 0x20, struct snd_rawmidi_status32), -#ifdef CONFIG_X86_X32 - SNDRV_RAWMIDI_IOCTL_STATUS_X32 = _IOWR('W', 0x20, struct snd_rawmidi_status_x32), -#endif /* CONFIG_X86_X32 */ + SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32 = _IOWR('W', 0x20, struct snd_rawmidi_status32), + SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64), }; static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -153,12 +112,10 @@ static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsign return snd_rawmidi_ioctl(file, cmd, (unsigned long)argp); case SNDRV_RAWMIDI_IOCTL_PARAMS32: return snd_rawmidi_ioctl_params_compat(rfile, argp); - case SNDRV_RAWMIDI_IOCTL_STATUS32: - return snd_rawmidi_ioctl_status_compat(rfile, argp); -#ifdef CONFIG_X86_X32 - case SNDRV_RAWMIDI_IOCTL_STATUS_X32: - return snd_rawmidi_ioctl_status_x32(rfile, argp); -#endif /* CONFIG_X86_X32 */ + case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32: + return snd_rawmidi_ioctl_status32(rfile, argp); + case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64: + return snd_rawmidi_ioctl_status_compat64(rfile, argp); } return -ENOIOCTLCMD; } From patchwork Tue Nov 12 15:16:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179219 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8258102ilf; Tue, 12 Nov 2019 07:18:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyyXwv1yPkW0ODhmwTNtc7TTjTBZ8VPkpajURpNMqssHja1J4yBLFDsKFgmPjpc5G/944ym X-Received: by 2002:a05:6402:706:: with SMTP id w6mr34323222edx.38.1573571930091; Tue, 12 Nov 2019 07:18:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571930; cv=none; d=google.com; s=arc-20160816; b=pKGEZCui2Hmu5SSKkyeGk0ZfKVj4J7q0b+ggTYE9/ObSrOxlVruudAmATzi0wpvIOG yZ1nC9pYupAcwXlgX51+FqbOWsCc486IvFCEEc1w2yIT2EJnciWXJxUCDxbT+vE1KHqH fqS1ojThN4A1MkFmlkW56BxZR92DwwVzKePRMEoii5qreEak5OguWO/kudd9hMAzsWKK wZZ8qXQPGJ6pMx+HzpUz1Ga0W4Z7EVMNWX6NgTfIuEPK+Lf8k1SeVYFDXyL0t4k1oaaG eTKgNT7Pv/VTEQuy0xPU5Xa0coYyz1uPDUBkCZRsXiOvn1mRl2viYSY7F2YAvbtwXDOQ TtdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2Z/3RC/eR1+nZr8rptqv7EDY0GVva6eOAKR4vj7dYTI=; b=CHP2NjyUvsH4mF8roZL5gAdQC06GZk4vbiB3fBcqPtjsKfIBUr4G3sMQ1lPuo0i85N CR/Q2iaf2HbdIJhwmA7r3UZbbg1fKeWt8rs0ynUDQcdy8A5A78IxeI/LpZ+mDWusUb/r ZDfKpdz5OfMNQ4IN/BRosYcp23dxH77ok68LbSv8aAxYbcSiNjiP+MxLE7Wp4qi9x7hH EGoBBgocHFwiATfa8Qw9YPt6xzyhVD9nSmsEuAynkToPzcrYlB7VqCO85BhsQWMNrfhh S3gP1cyFQcDz56F3Mte/7ozUKAjV4FSPAPgCMOFVcoBa6pnnUyt4DwLhyzZ6o3Raj4AV 2YpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.44; Tue, 12 Nov 2019 07:18:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727334AbfKLPSh (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:37 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:48109 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727284AbfKLPSf (ORCPT ); Tue, 12 Nov 2019 10:18:35 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MoNyA-1i6Fhy0Hd2-00oryL; Tue, 12 Nov 2019 16:16:58 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Baolin Wang , Arnd Bergmann Subject: [PATCH v6 6/8] ALSA: Avoid using timespec for struct snd_timer_tread Date: Tue, 12 Nov 2019 16:16:40 +0100 Message-Id: <20191112151642.680072-7-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:8tyWGY2E1T7Je1mDQRXAm/1XcX+3F+kX/ls4nsz4wW4vAHm5gYl P42VGz0CneqNn5ggJFZQAbD08pMgGu7BgKZd03vt976a0Jomdux0ePiJdT02EfQVo0gCA0B UTlhE9vkJUtADiXwiE+O3IY4BkL1uCyUSRUYpP488Tu7EZ1j5SKIpaaLvQtOXcEeoOQwIZS NG1tEHesOONy74q3B/T8Q== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:HR4+05j5RwY=:QFU4VqXlQ5E+FHGHZa/K3r vIHskQd0+big1nEOudlzs9ZOhn2XHsr+AxOAKDCEnBrtpSV5sOPcFtOjX8+XeEmyZaOgHQrZt BzvqsEwJ0BUNTh+/1k4BZ4fWCA0YmndV0vCdIn8wWGeJ2sTVjyZVvdWcXzjSLWGWwV506rCFr 6vu4G3kskwVMBqceyVp8KT4C0qrdjbYd8qri07q6jYXJwf4kYPaHWP/1dyD3GbizemWK+VpOg huF0W/PIckR+1ziFwr5yfZh7XbcbM/R/ODCZzBge32WZVpxoaJKB7698s8uE567U4PawX7Hpx pmiQH5lyT2OHKqGQPXrw3d8T2gUjSOsuvJOiQ1wTYgu0g3f2zzfw3a2sCkLKMOY8p/fefdUy7 Gk3Kq7IABWAHA7uLcRVr/VDvj6+j+slmyUhGiWVCUBcXShc3ki6MiKzaDuLBuJLTaOlrgN5N8 12Kh3mDK+FsRq6166DZEETOWoCqiz1TZAz39YzHDNA51V+sWVTqP6Awj6AQNZ/Wh/tfq78nrw hzaT8ALQv3csongl1X4kbriCTJQqynWxMhXndyBwdJMe4crTHfKXJWIKRleh+uHMh07KTPSvB mc1vs0YpswlnIqvUVSlhcsvEZvTW28qYjF4fdVg6/M0hdyfS+N4wAn8KA24vYac9b8UzdqKnT 0vIug1dzwZBcx/0FpqqY/OJPB3g4Q9S9caSTVIha+Gelml3zU5AS94kMSkyzamB8/1+KkcE6C sYc19K7x4KLiyloiZeRHieP8moZnQph+LoA3aXOFgUzFQE0cuIZBdKunGk7pOR7j75u9SlMQz XqxmMgoEhHDVBQYAk+d1JXZfs8LHm8rErg+/VJEY2C7Zvu0+YN6/+pgXhjjg2KuuV04XdTVxn tealbwHNS0ltJT5O0QiA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang The struct snd_timer_tread will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Since the struct snd_timer_tread is passed through read() rather than ioctl(), and the read syscall has no command number that lets us pick between the 32-bit or 64-bit version of this structure. Thus we introduced one new command SNDRV_TIMER_IOCTL_TREAD64 and new struct snd_timer_tread64 replacing timespec with s64 type to handle 64bit time_t. That means we will set tu->tread = TREAD_FORMAT_64BIT when user space has a 64bit time_t, then we will copy to user with struct snd_timer_tread64. Otherwise we will use 32bit time_t variables when copying to user. Moreover this patch replaces timespec type with timespec64 type and related y2038 safe APIs. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 15 +++- sound/core/timer.c | 149 +++++++++++++++++++++++++++--------- sound/core/timer_compat.c | 5 +- 3 files changed, 130 insertions(+), 39 deletions(-) -- 2.20.0 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index cb830813da5d..8ce73fb629e8 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -780,7 +780,7 @@ struct snd_timer_status { #define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int) #define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id) -#define SNDRV_TIMER_IOCTL_TREAD _IOW('T', 0x02, int) +#define SNDRV_TIMER_IOCTL_TREAD_OLD _IOW('T', 0x02, int) #define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo) #define SNDRV_TIMER_IOCTL_GPARAMS _IOW('T', 0x04, struct snd_timer_gparams) #define SNDRV_TIMER_IOCTL_GSTATUS _IOWR('T', 0x05, struct snd_timer_gstatus) @@ -793,6 +793,15 @@ struct snd_timer_status { #define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1) #define SNDRV_TIMER_IOCTL_CONTINUE _IO('T', 0xa2) #define SNDRV_TIMER_IOCTL_PAUSE _IO('T', 0xa3) +#define SNDRV_TIMER_IOCTL_TREAD64 _IOW('T', 0xa4, int) + +#if __BITS_PER_LONG == 64 +#define SNDRV_TIMER_IOCTL_TREAD SNDRV_TIMER_IOCTL_TREAD_OLD +#else +#define SNDRV_TIMER_IOCTL_TREAD ((sizeof(__kernel_long_t) >= sizeof(time_t)) ? \ + SNDRV_TIMER_IOCTL_TREAD_OLD : \ + SNDRV_TIMER_IOCTL_TREAD64) +#endif struct snd_timer_read { unsigned int resolution; @@ -818,11 +827,15 @@ enum { SNDRV_TIMER_EVENT_MRESUME = SNDRV_TIMER_EVENT_RESUME + 10, }; +#ifndef __KERNEL__ struct snd_timer_tread { int event; + __u8 pad1[sizeof(time_t) - sizeof(int)]; struct timespec tstamp; unsigned int val; + __u8 pad2[sizeof(time_t) - sizeof(unsigned int)]; }; +#endif /**************************************************************************** * * diff --git a/sound/core/timer.c b/sound/core/timer.c index 921f4ae2f9bf..19a68cbbfbcb 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -44,6 +44,28 @@ MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for t MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER); MODULE_ALIAS("devname:snd/timer"); +enum timer_tread_format { + TREAD_FORMAT_NONE = 0, + TREAD_FORMAT_TIME64, + TREAD_FORMAT_TIME32, +}; + +struct snd_timer_tread32 { + int event; + s32 tstamp_sec; + s32 tstamp_nsec; + unsigned int val; +}; + +struct snd_timer_tread64 { + int event; + u8 pad1[4]; + s64 tstamp_sec; + s64 tstamp_nsec; + unsigned int val; + u8 pad2[4]; +}; + struct snd_timer_user { struct snd_timer_instance *timeri; int tread; /* enhanced read with timestamps and events */ @@ -55,7 +77,7 @@ struct snd_timer_user { int queue_size; bool disconnected; struct snd_timer_read *queue; - struct snd_timer_tread *tqueue; + struct snd_timer_tread64 *tqueue; spinlock_t qlock; unsigned long last_resolution; unsigned int filter; @@ -1326,7 +1348,7 @@ static void snd_timer_user_interrupt(struct snd_timer_instance *timeri, } static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu, - struct snd_timer_tread *tread) + struct snd_timer_tread64 *tread) { if (tu->qused >= tu->queue_size) { tu->overrun++; @@ -1343,7 +1365,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, unsigned long resolution) { struct snd_timer_user *tu = timeri->callback_data; - struct snd_timer_tread r1; + struct snd_timer_tread64 r1; unsigned long flags; if (event >= SNDRV_TIMER_EVENT_START && @@ -1353,7 +1375,8 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, return; memset(&r1, 0, sizeof(r1)); r1.event = event; - r1.tstamp = timespec64_to_timespec(*tstamp); + r1.tstamp_sec = tstamp->tv_sec; + r1.tstamp_nsec = tstamp->tv_nsec; r1.val = resolution; spin_lock_irqsave(&tu->qlock, flags); snd_timer_user_append_to_tqueue(tu, &r1); @@ -1375,7 +1398,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, unsigned long ticks) { struct snd_timer_user *tu = timeri->callback_data; - struct snd_timer_tread *r, r1; + struct snd_timer_tread64 *r, r1; struct timespec64 tstamp; int prev, append = 0; @@ -1396,7 +1419,8 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { r1.event = SNDRV_TIMER_EVENT_RESOLUTION; - r1.tstamp = timespec64_to_timespec(tstamp); + r1.tstamp_sec = tstamp.tv_sec; + r1.tstamp_nsec = tstamp.tv_nsec; r1.val = resolution; snd_timer_user_append_to_tqueue(tu, &r1); tu->last_resolution = resolution; @@ -1410,14 +1434,16 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->tqueue[prev]; if (r->event == SNDRV_TIMER_EVENT_TICK) { - r->tstamp = timespec64_to_timespec(tstamp); + r->tstamp_sec = tstamp.tv_sec; + r->tstamp_nsec = tstamp.tv_nsec; r->val += ticks; append++; goto __wake; } } r1.event = SNDRV_TIMER_EVENT_TICK; - r1.tstamp = timespec64_to_timespec(tstamp); + r1.tstamp_sec = tstamp.tv_sec; + r1.tstamp_nsec = tstamp.tv_nsec; r1.val = ticks; snd_timer_user_append_to_tqueue(tu, &r1); append++; @@ -1432,7 +1458,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, static int realloc_user_queue(struct snd_timer_user *tu, int size) { struct snd_timer_read *queue = NULL; - struct snd_timer_tread *tqueue = NULL; + struct snd_timer_tread64 *tqueue = NULL; if (tu->tread) { tqueue = kcalloc(size, sizeof(*tqueue), GFP_KERNEL); @@ -1860,11 +1886,11 @@ static int snd_timer_user_params(struct file *file, tu->qhead = tu->qtail = tu->qused = 0; if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { if (tu->tread) { - struct snd_timer_tread tread; + struct snd_timer_tread64 tread; memset(&tread, 0, sizeof(tread)); tread.event = SNDRV_TIMER_EVENT_EARLY; - tread.tstamp.tv_sec = 0; - tread.tstamp.tv_nsec = 0; + tread.tstamp_sec = 0; + tread.tstamp_nsec = 0; tread.val = 0; snd_timer_user_append_to_tqueue(tu, &tread); } else { @@ -1994,6 +2020,36 @@ static int snd_timer_user_pause(struct file *file) return 0; } +static int snd_timer_user_tread(void __user *argp, struct snd_timer_user *tu, + unsigned int cmd, bool compat) +{ + int __user *p = argp; + int xarg, old_tread; + + if (tu->timeri) /* too late */ + return -EBUSY; + if (get_user(xarg, p)) + return -EFAULT; + + old_tread = tu->tread; + + if (!xarg) + tu->tread = TREAD_FORMAT_NONE; + else if (cmd == SNDRV_TIMER_IOCTL_TREAD64 || + (IS_ENABLED(CONFIG_64BITS) && !compat)) + tu->tread = TREAD_FORMAT_TIME64; + else + tu->tread = TREAD_FORMAT_TIME32; + + if (tu->tread != old_tread && + realloc_user_queue(tu, tu->queue_size) < 0) { + tu->tread = old_tread; + return -ENOMEM; + } + + return 0; +} + enum { SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20), SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21), @@ -2002,7 +2058,7 @@ enum { }; static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) + unsigned long arg, bool compat) { struct snd_timer_user *tu; void __user *argp = (void __user *)arg; @@ -2014,23 +2070,9 @@ static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd, return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0; case SNDRV_TIMER_IOCTL_NEXT_DEVICE: return snd_timer_user_next_device(argp); - case SNDRV_TIMER_IOCTL_TREAD: - { - int xarg, old_tread; - - if (tu->timeri) /* too late */ - return -EBUSY; - if (get_user(xarg, p)) - return -EFAULT; - old_tread = tu->tread; - tu->tread = xarg ? 1 : 0; - if (tu->tread != old_tread && - realloc_user_queue(tu, tu->queue_size) < 0) { - tu->tread = old_tread; - return -ENOMEM; - } - return 0; - } + case SNDRV_TIMER_IOCTL_TREAD_OLD: + case SNDRV_TIMER_IOCTL_TREAD64: + return snd_timer_user_tread(argp, tu, cmd, compat); case SNDRV_TIMER_IOCTL_GINFO: return snd_timer_user_ginfo(file, argp); case SNDRV_TIMER_IOCTL_GPARAMS: @@ -2070,7 +2112,7 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, long ret; mutex_lock(&tu->ioctl_lock); - ret = __snd_timer_user_ioctl(file, cmd, arg); + ret = __snd_timer_user_ioctl(file, cmd, arg, false); mutex_unlock(&tu->ioctl_lock); return ret; } @@ -2086,13 +2128,28 @@ static int snd_timer_user_fasync(int fd, struct file * file, int on) static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, size_t count, loff_t *offset) { + struct snd_timer_tread64 *tread; + struct snd_timer_tread32 tread32; struct snd_timer_user *tu; long result = 0, unit; int qhead; int err = 0; tu = file->private_data; - unit = tu->tread ? sizeof(struct snd_timer_tread) : sizeof(struct snd_timer_read); + switch (tu->tread) { + case TREAD_FORMAT_TIME64: + unit = sizeof(struct snd_timer_tread64); + break; + case TREAD_FORMAT_TIME32: + unit = sizeof(struct snd_timer_tread32); + break; + case TREAD_FORMAT_NONE: + unit = sizeof(struct snd_timer_read); + break; + default: + return -ENOTSUPP; + } + mutex_lock(&tu->ioctl_lock); spin_lock_irq(&tu->qlock); while ((long)count - result >= unit) { @@ -2131,14 +2188,34 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, tu->qused--; spin_unlock_irq(&tu->qlock); - if (tu->tread) { - if (copy_to_user(buffer, &tu->tqueue[qhead], - sizeof(struct snd_timer_tread))) + tread = &tu->tqueue[qhead]; + + switch (tu->tread) { + case TREAD_FORMAT_TIME64: + if (copy_to_user(buffer, tread, + sizeof(struct snd_timer_tread64))) err = -EFAULT; - } else { + break; + case TREAD_FORMAT_TIME32: + memset(&tread32, 0, sizeof(tread32)); + tread32 = (struct snd_timer_tread32) { + .event = tread->event, + .tstamp_sec = tread->tstamp_sec, + .tstamp_sec = tread->tstamp_nsec, + .val = tread->val, + }; + + if (copy_to_user(buffer, &tread32, sizeof(tread32))) + err = -EFAULT; + break; + case TREAD_FORMAT_NONE: if (copy_to_user(buffer, &tu->queue[qhead], sizeof(struct snd_timer_read))) err = -EFAULT; + break; + default: + err = -ENOTSUPP; + break; } spin_lock_irq(&tu->qlock); diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index 20eef5bc304b..0103d16f6f9f 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -83,7 +83,8 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, switch (cmd) { case SNDRV_TIMER_IOCTL_PVERSION: - case SNDRV_TIMER_IOCTL_TREAD: + case SNDRV_TIMER_IOCTL_TREAD_OLD: + case SNDRV_TIMER_IOCTL_TREAD64: case SNDRV_TIMER_IOCTL_GINFO: case SNDRV_TIMER_IOCTL_GSTATUS: case SNDRV_TIMER_IOCTL_SELECT: @@ -97,7 +98,7 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, case SNDRV_TIMER_IOCTL_PAUSE: case SNDRV_TIMER_IOCTL_PAUSE_OLD: case SNDRV_TIMER_IOCTL_NEXT_DEVICE: - return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp); + return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp, true); case SNDRV_TIMER_IOCTL_GPARAMS32: return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: From patchwork Tue Nov 12 15:16:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179221 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8258344ilf; Tue, 12 Nov 2019 07:19:02 -0800 (PST) X-Google-Smtp-Source: APXvYqxSzxYduMSXiv7+I85rwfkymsIpyq5AmNTPpzYhqKQH26X0ZX6pZ4abzBY18lcfWR2U3/YD X-Received: by 2002:a50:8e43:: with SMTP id 3mr32872901edx.217.1573571942137; Tue, 12 Nov 2019 07:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571942; cv=none; d=google.com; s=arc-20160816; b=VwjvACEo+LKpD9CrJ9uPYF1KS2g4Ry4p0JrK2LaZixEWwwW8Jgh9OwAwDXrIy2Ju3Z /AKMJPjmd4RhcwZLNdM8Rmtu3AL+J53njTTyqqfVSSUfHCUaqqeCh5k8/FcobKZyrD1c pmOAsGVqBmH1Y+J88aHl1jBloUhXSutxhu2I8Dx3+KjOi6BLplXN01pVKJIYJljIM8mB hWFh2FZp5QLyUZyrhV1JtgZO6Y/zyVNlGKTz8KrtwxLXTySEHIGX3ljMjX3h+oZMIvTe RnyYDdNpyZGqQelQny7SZmUfuDzzbijB6opTmymGj8/u9pHOCSp1GRL5/0XXVRSa7mMw qnbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fp0mGS1PmCAsFo7YL/ATVOtIyvCf+8SpDdgSvGg1l00=; b=BfGh9kauq3lY+4bZ99g6wYJgHX2g7yAdjLTaKwR8Jk7UmbpsPaspMYfTR6Y/+aMLI3 ls3SO9At4Bzzk0FQfYigwmYAuECSI/CXcPxvQD0Vp4OUYpuNLuy+NcBtdkpeYDxIhLPm ZIV/R07R69TXBnb0/3VEBZ2k2aB86adMpiN2wEKrc38WuUQOgV63KiE6AD85QD7ju2yz Dgzj7xwJV73WeAgdNZrcmVbVcfXVYYI04Kxe4V+GRc8iIljWB2VSVzGTa/fE2Z7urq6x zY92ufSGbildjF8PNYY0e49k4aJQiOYCC6EH3TqDGVZjoktnSN8KGS9a5SV8W1CJmNzf QDJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.56; Tue, 12 Nov 2019 07:19:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727359AbfKLPSx (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:53 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:36145 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbfKLPSw (ORCPT ); Tue, 12 Nov 2019 10:18:52 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MvsMz-1heMlZ1bTr-00srMc; Tue, 12 Nov 2019 16:16:58 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Arnd Bergmann , Baolin Wang Subject: [PATCH v6 7/8] ALSA: move snd_pcm_ioctl_sync_ptr_compat into pcm_native.c Date: Tue, 12 Nov 2019 16:16:41 +0100 Message-Id: <20191112151642.680072-8-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dtqoaQwSKA1q63zq2NLtnzRRfdE4iOdCohvxz6SoA6GtAIprbQA QUkxbusXoMRs9YuevIRG06mGKr179ICD90ysX1I7kufOsgutVAajIKbMatzON5h+WEjI1mi 2ZlsS9yiCa8U853bBW2FL03aImgfAFOIKIwh8HFKG/537MkEos/GL/Vz7eOBNNVrVCx8dK8 SWX+rnoEZnmslK9br4B8Q== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:9b2k5ENw0xc=:nhmErBHh8bwn0ffdqcyE/g zu0F7nZ+WLIcXemXY8RTC8ibhVAw4HiH6LgfD7pYKW5Sm9R2bv92cE/O9lNH19Xt+/QYkFzd3 megGMJCMdjjSZ3D1FENgq5mSlqK2jyFkOjhUmA/AAm1pMJvrWl+jprM7kIFA8AP2/ktoqh1/D 5ZJeksLRVCGs1KnknXitwJGIM5bztr3P9xItJGbjRSOk9YoLanMpsRkmolX4Z588Bb7HZ1DcT WarsQmITagCDgzOWZ2y8eCyjBGGiDY4WB2IKkq+/kFUpaskyYuDfuYo8xmiF30kEksh+zyzxb EZnX9eDH1FnbSw9ExWmBpDbWapFHqthnEKarFlg2S0u5wcB1I462xFXBmm3NdQzglCMjBvlWQ b3Uxqaopy3OS4PoaK99Vw+JFdVwp0EMdWMx4dn/jA9hhWt3eoufg6WEN7tWxfzgT0TNvnH4HJ zjXE3t/aJDCJZy3KMC6TkfehISPQ/SaET2GOOnRXk3TG48VB5CDOZwqPF2ojLrMXJc7rSwcCH 8ilTC9O+nkeAUCFPQwfISZdM6oDOSs8JLjL2NWORjuXtOAoPfJ190KC22T4JnBIHBMAtw5wmg wjOxkQU5zqYIgDjM59lH8vsyKUlr26KEiNNbVQokKkrBuORzRLpyVpMz3aKCVxURhdNHAgz8g P9HlrhAw0JMEM/DU260goiUcNlDWIew4caW9+A2YWW67SGDWb0vBeTzxX/0vMwpcdiOHKhkFT A4sJrPUMpvC0XFbqf/8vmPFORf+04bzYYs5OorAgTHjXO5EjdPkfcKIEVIekjmy4SGr+qfsFp oMEhuqdoJGBr8wcKqCjnYYtqSZCUefHUuboyG6TgpGiil5E153mRfRgvMDP7dPmUHRVPt7X3w DXo3l52tPUYKwqSWxyng== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparation patch, moving the compat handler for snd_pcm_ioctl_sync_ptr_compat from pcm_compat.c to pcm_native.c. No other changes are indented. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- sound/core/pcm_compat.c | 98 -------------------------------------- sound/core/pcm_native.c | 101 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 98 deletions(-) -- 2.20.0 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index 2671658442ea..6a2e5ea145e6 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -83,19 +83,6 @@ struct snd_pcm_sw_params32 { unsigned char reserved[56]; }; -/* recalcuate the boundary within 32bit */ -static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) -{ - snd_pcm_uframes_t boundary; - - if (! runtime->buffer_size) - return 0; - boundary = runtime->buffer_size; - while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) - boundary *= 2; - return boundary; -} - static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream, struct snd_pcm_sw_params32 __user *src) { @@ -388,91 +375,6 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream, return err; } - -struct snd_pcm_mmap_status32 { - s32 state; - s32 pad1; - u32 hw_ptr; - struct compat_timespec tstamp; - s32 suspended_state; - struct compat_timespec audio_tstamp; -} __attribute__((packed)); - -struct snd_pcm_mmap_control32 { - u32 appl_ptr; - u32 avail_min; -}; - -struct snd_pcm_sync_ptr32 { - u32 flags; - union { - struct snd_pcm_mmap_status32 status; - unsigned char reserved[64]; - } s; - union { - struct snd_pcm_mmap_control32 control; - unsigned char reserved[64]; - } c; -} __attribute__((packed)); - -static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, - struct snd_pcm_sync_ptr32 __user *src) -{ - struct snd_pcm_runtime *runtime = substream->runtime; - volatile struct snd_pcm_mmap_status *status; - volatile struct snd_pcm_mmap_control *control; - u32 sflags; - struct snd_pcm_mmap_control scontrol; - struct snd_pcm_mmap_status sstatus; - snd_pcm_uframes_t boundary; - int err; - - if (snd_BUG_ON(!runtime)) - return -EINVAL; - - if (get_user(sflags, &src->flags) || - get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || - get_user(scontrol.avail_min, &src->c.control.avail_min)) - return -EFAULT; - if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { - err = snd_pcm_hwsync(substream); - if (err < 0) - return err; - } - status = runtime->status; - control = runtime->control; - boundary = recalculate_boundary(runtime); - if (! boundary) - boundary = 0x7fffffff; - snd_pcm_stream_lock_irq(substream); - /* FIXME: we should consider the boundary for the sync from app */ - if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) - control->appl_ptr = scontrol.appl_ptr; - else - scontrol.appl_ptr = control->appl_ptr % boundary; - if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) - control->avail_min = scontrol.avail_min; - else - scontrol.avail_min = control->avail_min; - sstatus.state = status->state; - sstatus.hw_ptr = status->hw_ptr % boundary; - sstatus.tstamp = status->tstamp; - sstatus.suspended_state = status->suspended_state; - sstatus.audio_tstamp = status->audio_tstamp; - snd_pcm_stream_unlock_irq(substream); - if (put_user(sstatus.state, &src->s.status.state) || - put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || - put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - compat_put_timespec(&sstatus.audio_tstamp, - &src->s.status.audio_tstamp) || - put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || - put_user(scontrol.avail_min, &src->c.control.avail_min)) - return -EFAULT; - - return 0; -} - #ifdef CONFIG_X86_X32 /* X32 ABI has 64bit timespec and 64bit alignment */ struct snd_pcm_mmap_status_x32 { diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 2c8c9b91677a..cad90d9ce9da 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -4,6 +4,7 @@ * Copyright (c) by Jaroslav Kysela */ +#include #include #include #include @@ -2846,6 +2847,106 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, return 0; } +#ifdef CONFIG_COMPAT +struct snd_pcm_mmap_status32 { + s32 state; + s32 pad1; + u32 hw_ptr; + struct compat_timespec tstamp; + s32 suspended_state; + struct compat_timespec audio_tstamp; +} __attribute__((packed)); + +struct snd_pcm_mmap_control32 { + u32 appl_ptr; + u32 avail_min; +}; + +struct snd_pcm_sync_ptr32 { + u32 flags; + union { + struct snd_pcm_mmap_status32 status; + unsigned char reserved[64]; + } s; + union { + struct snd_pcm_mmap_control32 control; + unsigned char reserved[64]; + } c; +} __attribute__((packed)); + +/* recalcuate the boundary within 32bit */ +static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) +{ + snd_pcm_uframes_t boundary; + + if (! runtime->buffer_size) + return 0; + boundary = runtime->buffer_size; + while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) + boundary *= 2; + return boundary; +} + +static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, + struct snd_pcm_sync_ptr32 __user *src) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + volatile struct snd_pcm_mmap_status *status; + volatile struct snd_pcm_mmap_control *control; + u32 sflags; + struct snd_pcm_mmap_control scontrol; + struct snd_pcm_mmap_status sstatus; + snd_pcm_uframes_t boundary; + int err; + + if (snd_BUG_ON(!runtime)) + return -EINVAL; + + if (get_user(sflags, &src->flags) || + get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || + get_user(scontrol.avail_min, &src->c.control.avail_min)) + return -EFAULT; + if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { + err = snd_pcm_hwsync(substream); + if (err < 0) + return err; + } + status = runtime->status; + control = runtime->control; + boundary = recalculate_boundary(runtime); + if (! boundary) + boundary = 0x7fffffff; + snd_pcm_stream_lock_irq(substream); + /* FIXME: we should consider the boundary for the sync from app */ + if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) + control->appl_ptr = scontrol.appl_ptr; + else + scontrol.appl_ptr = control->appl_ptr % boundary; + if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) + control->avail_min = scontrol.avail_min; + else + scontrol.avail_min = control->avail_min; + sstatus.state = status->state; + sstatus.hw_ptr = status->hw_ptr % boundary; + sstatus.tstamp = status->tstamp; + sstatus.suspended_state = status->suspended_state; + sstatus.audio_tstamp = status->audio_tstamp; + snd_pcm_stream_unlock_irq(substream); + if (put_user(sstatus.state, &src->s.status.state) || + put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || + compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.suspended_state, &src->s.status.suspended_state) || + compat_put_timespec(&sstatus.audio_tstamp, + &src->s.status.audio_tstamp) || + put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || + put_user(scontrol.avail_min, &src->c.control.avail_min)) + return -EFAULT; + + return 0; +} +#define __SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), +#endif + static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { struct snd_pcm_runtime *runtime = substream->runtime; From patchwork Tue Nov 12 15:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179220 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8258231ilf; Tue, 12 Nov 2019 07:18:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwr5qbvuVoTEumTAtUS6cCm2hp1sVMU+HxL40fyKlnM35XfC7bFqF64XJCXGJvNmW2AgVEg X-Received: by 2002:a50:8264:: with SMTP id 91mr33165325edf.69.1573571936490; Tue, 12 Nov 2019 07:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573571936; cv=none; d=google.com; s=arc-20160816; b=VZCidF+sP5O4HafB5EpdJJL3DlCIzu+gu27zJMOfwB2lm2Y7Uw8ALNUebhn0LonYyh P2agUQ0LXmU8AFQ1q5J7L78DZ4/bP5+zmZSk3RmlTkgFJmcd39IYZukKYsYHevlRqF4k 1hMV7qZU+x69any6NU1uKB2jM8DlJwhh6XIQ/9he8pQwzui0vcEkHrpH4KMJmYXPHj22 0l46cRliVk+6AnpGbZyFzdYHNERvTOhTO6zz8uRicL5PNyaLAQ8uw7U/l+tfdhYh+iem pSUqXAiq5DoENs6wjVJNOMh7G/tjkeNqzoDPB7IkQaBIBDrN+rJhT24QZr4Gfk0go9hz neTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=m7YVNyCqw7+RnFvPP0OTSpjXzGpZcU3V490IZCYXMoQ=; b=OX3c2F+pHEmyaI+Jx8KKxpiPBUloWOJukE3RojXwk6RdB/NolImpRqnidPNy+9Bpig r+ejFnHIA9D/wGn9D/JhlfweHehaOc+VH2te3BvnKyESU71okrhJsRJwXMkLx7kiroJ2 dtHQxTfQsmE1e2vewfSU6XHGMNGAbbiq9geC8RPVZOYlUY+IzFLV6w/8fUpgYWTTmj+N 9dgLlz5sLygmU454iEoBD3GcxCjTOV/54Bnb2i80EMTB7pmAMyW+C8M7LQOsdXn1Kh8t gDi6+SI5PGNafOXc/EsLhR4WYjNPTUvkxA0gIb+B0O/W2C284IMxcaG0jZP6ySL8n/sl zGIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si173912ejh.75.2019.11.12.07.18.50; Tue, 12 Nov 2019 07:18:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727168AbfKLPSl (ORCPT + 26 others); Tue, 12 Nov 2019 10:18:41 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:51557 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbfKLPSg (ORCPT ); Tue, 12 Nov 2019 10:18:36 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1N95mL-1hrcJ32ngN-0166uc; Tue, 12 Nov 2019 16:16:58 +0100 From: Arnd Bergmann To: alsa-devel@alsa-project.org, Takashi Iwai Cc: Baolin Wang , y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , Arnd Bergmann , Baolin Wang Subject: [PATCH v6 8/8] ALSA: add new 32-bit layout for snd_pcm_mmap_status/control Date: Tue, 12 Nov 2019 16:16:42 +0100 Message-Id: <20191112151642.680072-9-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191112151642.680072-1-arnd@arndb.de> References: <20191112151642.680072-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3JDwYcuvhs/2INInb973esdgfypGwSZXzmmjwJNxboJ6p+MjLBO eP+C+GwbKKlvzA8OcaRCXRKk0BQMDks5U56ijfIW9Rt8eBfEnZ7FQET1aAHgqMkSnrp8u4V WcVyCt2I1ZLlVvofsO/aWYncEhghT4klifmXUhCYgixHo4/7JR+vGQXZ+gBUhzyD2tu/ogb lcThHd1/TzbY+iFoeS/gA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:wEZJNo+vaUE=:W44iqgcFY5qr50T32oSvsx CuPwbkLSOEGwTC1C7J7e/Ty2hzeSoJUhyd6k/r8ID80dtadqX18sFdRXPzF/5E5QRO9XEFu/v oUQoimyxDe0eDfAFmIYJCD9d7EswFrAXiKjNTrpWXRL9gll0WzP24+c7EVhiwl3Su2IV02aCD KE5LNmAsXdURsdgH7Q1t2UnxK0WOGTZ0J4gULBii9lGoAS/lvtjIG5GisMUEAHA27kQziN2ie zatWlHh7J345yb4WB9cki/Q5vqpXRcmF1EfB6acSippyVvMpHHV9bDgHEgJjy0BKKPGV9SJ3N uzgdoWig9Y4zXjRdJe9/ZT1JqJnUpujis6bGIn0PWKqJhAuKO1vf+57WtTxLrY3yU8J6Z59I8 Vc7FUZC9Jr7Ku1Ujvk61o6OYH9s8kOTb5/wU/0Gk7LTFyBE+I/+Vyw4Y/dVeye/g6MZRWRbkx 6HrnG7sKZ6HaK0hq4nxlIYQMJ8mH5rIQvxGYf89yqn4v1B0UWxXC/EhKaL6tSCR10sx3seEZH HKS0c0hZXfaU7KeR4ewSh5okcH8wvu9rm8Opv2ykTWoJXJ2zxn8c9yacrC/CdHAUIx1UdXEkn DWEyYaVExn/vpND9F/D89+SRo0l/9dY1NJ5fwF4YKy1/lht4DdCFO5OWJ5bJ4T2cu0Ds0P+XJ DTkxlBamH/U8Q4SUDENc95oxyWRbRPuEFl4KRHt1RIi6F8/alT5mWRgPmGUjgLcVovQABMWV0 SET8ygquOSTzxTWiWiY3Wo/bdW58N1cux9uWwuHn7yaEssuNqSzkgnG4G2a/FPLw7lOSwqdA2 E8cPWJW2rsMIr6R7+pM1P6QLNf3YVPKPlwGYNbZnXoKZm+Fmv74m3y3D3cbIh7hv3vIUjUIdo XqvD/EIg0tUomxJFJGPQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The snd_pcm_mmap_status and snd_pcm_mmap_control interfaces are one of the trickiest areas to get right when moving to 64-bit time_t in user space. The snd_pcm_mmap_status structure layout is incompatible with user space that uses a 64-bit time_t, so we need a new layout for it. Since the SNDRV_PCM_IOCTL_SYNC_PTR ioctl combines it with snd_pcm_mmap_control into snd_pcm_sync_ptr, we need to change those two as well. Both structures are also exported via an mmap() operation on certain architectures, and this suffers from incompatibility between 32-bit and 64-bit user space. As we have to change both structures anyway, this is a good opportunity to fix the mmap() problem as well, so let's standardize on the existing 64-bit layout of the structure where possible. The downside is that we lose mmap() support for existing 32-bit x86 and powerpc applications, adding that would introduce very noticeable runtime overhead and complexity. My assumption here is that not too many people will miss the removed feature, given that: - Almost all x86 and powerpc users these days are on 64-bit kernels, the majority of today's 32-bit users are on architectures that never supported mmap (ARM, MIPS, ...). - It never worked in compat mode (it was intentionally disabled there) - The application already needs to work with a fallback to SNDRV_PCM_IOCTL_SYNC_PTR, which will keep working with both the old and new structure layout. Both the ioctl() and mmap() based interfaces are changed at the same time, as they are based on the same structures. Unlike other interfaces, we change the uapi header to export both the traditional structure and a version that is portable between 32-bit and 64-bit user space code and that corresponds to the existing 64-bit layout. We further check the __USE_TIME_BITS64 macro that will be defined by future C library versions whenever we use the new time_t definition, so any existing user space source code will not see any changes until it gets rebuilt against a new C library. However, the new structures are all visible in addition to the old ones, allowing applications to explicitly request the new structures. In order to detect the difference between the old snd_pcm_mmap_status and the new __snd_pcm_mmap_status64 structure from the ioctl command number, we rely on one quirk in the structure definition: snd_pcm_mmap_status must be aligned to alignof(time_t), which leads the compiler to insert four bytes of padding in struct snd_pcm_sync_ptr after 'flags' and a corresponding change in the size of snd_pcm_sync_ptr itself. On x86-32 (and only there), the compiler doesn't use 64-bit alignment in structure, so I'm adding an explicit pad in the structure that has no effect on the existing 64-bit architectures but ensures that the layout matches for x86. The snd_pcm_uframes_t type compatibility requires another hack: we can't easily make that 64 bit wide, so I leave the type as 'unsigned long', but add padding before and after it, to ensure that the data is properly aligned to the respective 64-bit field in the in-kernel structure. For the SNDRV_PCM_MMAP_OFFSET_STATUS/CONTROL constants that are used as the virtual file offset in the mmap() function, we also have to introduce new constants that depend on hte __USE_TIME_BITS64 macro: The existing macros are renamed to SNDRV_PCM_MMAP_OFFSET_STATUS_OLD and SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD, they continue to work fine on 64-bit architectures, but stop working on native 32-bit user space. The replacement _NEW constants are now used by default for user space built with __USE_TIME_BITS64, those now work on all new kernels for x86, ppc and alpha (32 and 64 bit, native and compat). It might be a good idea for a future alsa-lib to support both the _OLD and _NEW macros and use the corresponding structures directly. Unmodified alsa-lib source code will retain the current behavior, so it will no longer be able to use mmap() for the status/control structures on 32-bit systems, until either the C library gets updated to 64-bit time_t or alsa-lib gets updated to support both mmap() layouts. Co-developed-with: Baolin Wang Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 106 ++++++++++++++++++++++++++++++++---- sound/core/pcm_compat.c | 30 +++++----- sound/core/pcm_lib.c | 10 ++-- sound/core/pcm_native.c | 39 ++++++++----- 4 files changed, 143 insertions(+), 42 deletions(-) -- 2.20.0 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 8ce73fb629e8..d26b70d0fb57 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -35,6 +35,8 @@ #include #endif +#include + /* * protocol version */ @@ -301,7 +303,9 @@ typedef int __bitwise snd_pcm_subformat_t; #define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ #define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ - +#if (__BITS_PER_LONG == 32 && defined(__USE_TIME_BITS64)) || defined __KERNEL__ +#define __SND_STRUCT_TIME64 +#endif typedef int __bitwise snd_pcm_state_t; #define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */ @@ -317,8 +321,17 @@ typedef int __bitwise snd_pcm_state_t; enum { SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000, - SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000, - SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_OLD = 0x80000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD = 0x81000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_NEW = 0x82000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW = 0x83000000, +#ifdef __SND_STRUCT_TIME64 + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_NEW, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW, +#else + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_OLD, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD, +#endif }; union snd_pcm_sync_id { @@ -477,16 +490,42 @@ struct snd_pcm_status { }; #endif -struct snd_pcm_mmap_status { +/* + * For mmap operations, we need the 64-bit layout, both for compat mode, + * and for y2038 compatibility. For 64-bit applications, the two definitions + * are identical, so we keep the traditional version. + */ +#ifdef __SND_STRUCT_TIME64 +#define __snd_pcm_mmap_status64 snd_pcm_mmap_status +#define __snd_pcm_mmap_control64 snd_pcm_mmap_control +#define __snd_pcm_sync_ptr64 snd_pcm_sync_ptr +#define __snd_timespec64 timespec +struct __snd_timespec { + __s32 tv_sec; + __s32 tv_nsec; +}; +#else +#define __snd_pcm_mmap_status snd_pcm_mmap_status +#define __snd_pcm_mmap_control snd_pcm_mmap_control +#define __snd_pcm_sync_ptr snd_pcm_sync_ptr +#define __snd_timespec timespec +struct __snd_timespec64 { + __s64 tv_sec; + __s64 tv_nsec; +}; + +#endif + +struct __snd_pcm_mmap_status { snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ int pad1; /* Needed for 64 bit alignment */ snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ - struct timespec tstamp; /* Timestamp */ + struct __snd_timespec tstamp; /* Timestamp */ snd_pcm_state_t suspended_state; /* RO: suspended stream state */ - struct timespec audio_tstamp; /* from sample counter or wall clock */ + struct __snd_timespec audio_tstamp; /* from sample counter or wall clock */ }; -struct snd_pcm_mmap_control { +struct __snd_pcm_mmap_control { snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ }; @@ -495,14 +534,59 @@ struct snd_pcm_mmap_control { #define SNDRV_PCM_SYNC_PTR_APPL (1<<1) /* get appl_ptr from driver (r/w op) */ #define SNDRV_PCM_SYNC_PTR_AVAIL_MIN (1<<2) /* get avail_min from driver */ -struct snd_pcm_sync_ptr { +struct __snd_pcm_sync_ptr { unsigned int flags; union { - struct snd_pcm_mmap_status status; + struct __snd_pcm_mmap_status status; + unsigned char reserved[64]; + } s; + union { + struct __snd_pcm_mmap_control control; + unsigned char reserved[64]; + } c; +}; + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN) +typedef char __pad_before_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +typedef char __pad_after_uframe[0]; +#endif + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) +typedef char __pad_before_uframe[0]; +typedef char __pad_after_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +#endif + +struct __snd_pcm_mmap_status64 { + __s32 state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + __u32 pad1; /* Needed for 64 bit alignment */ + __pad_before_uframe __pad1; + snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ + __pad_after_uframe __pad2; + struct __snd_timespec64 tstamp; /* Timestamp */ + __s32 suspended_state; /* RO: suspended stream state */ + __u32 pad3; /* Needed for 64 bit alignment */ + struct __snd_timespec64 audio_tstamp; /* sample counter or wall clock */ +}; + +struct __snd_pcm_mmap_control64 { + __pad_before_uframe __pad1; + snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ + __pad_before_uframe __pad2; + + __pad_before_uframe __pad3; + snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ + __pad_after_uframe __pad4; +}; + +struct __snd_pcm_sync_ptr64 { + __u32 flags; + __u32 pad1; + union { + struct __snd_pcm_mmap_status64 status; unsigned char reserved[64]; } s; union { - struct snd_pcm_mmap_control control; + struct __snd_pcm_mmap_control64 control; unsigned char reserved[64]; } c; }; @@ -587,6 +671,8 @@ enum { #define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status) #define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t) #define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22) +#define __SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct __snd_pcm_sync_ptr) +#define __SNDRV_PCM_IOCTL_SYNC_PTR64 _IOWR('A', 0x23, struct __snd_pcm_sync_ptr64) #define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr) #define SNDRV_PCM_IOCTL_STATUS_EXT _IOWR('A', 0x24, struct snd_pcm_status) #define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info) diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index 6a2e5ea145e6..967c689fb8da 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -178,8 +178,6 @@ struct compat_snd_pcm_status64 { unsigned char reserved[52-4*sizeof(s64)]; } __packed; -#define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst)) - static int snd_pcm_status_user_compat64(struct snd_pcm_substream *substream, struct compat_snd_pcm_status64 __user *src, bool ext) @@ -382,10 +380,12 @@ struct snd_pcm_mmap_status_x32 { s32 pad1; u32 hw_ptr; u32 pad2; /* alignment */ - struct timespec tstamp; + s64 tstamp_sec; + s64 tstamp_nsec; s32 suspended_state; s32 pad3; - struct timespec audio_tstamp; + s64 audio_tstamp_sec; + s64 audio_tstamp_nsec; } __packed; struct snd_pcm_mmap_control_x32 { @@ -453,9 +453,11 @@ static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) || + put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - put_timespec(&sstatus.audio_tstamp, &src->s.status.audio_tstamp) || + put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) || + put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; @@ -480,7 +482,6 @@ enum { SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32), SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32), SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32), - SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64), SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64), #ifdef CONFIG_X86_X32 @@ -504,8 +505,8 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l /* * When PCM is used on 32bit mode, we need to disable - * mmap of PCM status/control records because of the size - * incompatibility. + * mmap of the old PCM status/control records because + * of the size incompatibility. */ pcm_file->no_compat_mmap = 1; @@ -527,6 +528,13 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l case SNDRV_PCM_IOCTL_XRUN: case SNDRV_PCM_IOCTL_LINK: case SNDRV_PCM_IOCTL_UNLINK: + case __SNDRV_PCM_IOCTL_SYNC_PTR32: + return snd_pcm_common_ioctl(file, substream, cmd, argp); + case __SNDRV_PCM_IOCTL_SYNC_PTR64: +#ifdef CONFIG_X86_X32 + if (in_x32_syscall()) + return snd_pcm_ioctl_sync_ptr_x32(substream, argp); +#endif /* CONFIG_X86_X32 */ return snd_pcm_common_ioctl(file, substream, cmd, argp); case SNDRV_PCM_IOCTL_HW_REFINE32: return snd_pcm_ioctl_hw_params_compat(substream, 1, argp); @@ -538,8 +546,6 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_status_user32(substream, argp, false); case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: return snd_pcm_status_user32(substream, argp, true); - case SNDRV_PCM_IOCTL_SYNC_PTR32: - return snd_pcm_ioctl_sync_ptr_compat(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: return snd_pcm_ioctl_channel_info_compat(substream, argp); case SNDRV_PCM_IOCTL_WRITEI_FRAMES32: @@ -561,8 +567,6 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64: return snd_pcm_status_user_compat64(substream, argp, true); #ifdef CONFIG_X86_X32 - case SNDRV_PCM_IOCTL_SYNC_PTR_X32: - return snd_pcm_ioctl_sync_ptr_x32(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32: return snd_pcm_ioctl_channel_info_x32(substream, argp); #endif /* CONFIG_X86_X32 */ diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 42cc1b71d1e3..47dcf6d4a680 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -148,7 +148,8 @@ void __snd_pcm_xrun(struct snd_pcm_substream *substream) struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); - runtime->status->tstamp = timespec64_to_timespec(tstamp); + runtime->status->tstamp.tv_sec = tstamp.tv_sec; + runtime->status->tstamp.tv_nsec = tstamp.tv_nsec; } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { @@ -238,9 +239,10 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { - runtime->status->audio_tstamp = - timespec64_to_timespec(*audio_tstamp); - runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); + runtime->status->audio_tstamp.tv_sec = audio_tstamp->tv_sec; + runtime->status->audio_tstamp.tv_nsec = audio_tstamp->tv_nsec; + runtime->status->tstamp.tv_sec = curr_tstamp->tv_sec; + runtime->status->tstamp.tv_nsec = curr_tstamp->tv_nsec; } diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index cad90d9ce9da..2be602c44a47 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2847,14 +2847,15 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, return 0; } -#ifdef CONFIG_COMPAT struct snd_pcm_mmap_status32 { s32 state; s32 pad1; u32 hw_ptr; - struct compat_timespec tstamp; + s32 tstamp_sec; + s32 tstamp_nsec; s32 suspended_state; - struct compat_timespec audio_tstamp; + s32 audio_tstamp_sec; + s32 audio_tstamp_nsec; } __attribute__((packed)); struct snd_pcm_mmap_control32 { @@ -2934,18 +2935,18 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) || + put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - compat_put_timespec(&sstatus.audio_tstamp, - &src->s.status.audio_tstamp) || + put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) || + put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; return 0; } -#define __SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), -#endif +#define __SNDRV_PCM_IOCTL_SYNC_PTR32 _IOWR('A', 0x23, struct snd_pcm_sync_ptr32) static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { @@ -3115,7 +3116,9 @@ static int snd_pcm_common_ioctl(struct file *file, return -EFAULT; return 0; } - case SNDRV_PCM_IOCTL_SYNC_PTR: + case __SNDRV_PCM_IOCTL_SYNC_PTR32: + return snd_pcm_ioctl_sync_ptr_compat(substream, arg); + case __SNDRV_PCM_IOCTL_SYNC_PTR64: return snd_pcm_sync_ptr(substream, arg); #ifdef CONFIG_SND_SUPPORT_OLD_API case SNDRV_PCM_IOCTL_HW_REFINE_OLD: @@ -3453,8 +3456,6 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file) { - if (pcm_file->no_compat_mmap) - return false; /* See pcm_control_mmap_allowed() below. * Since older alsa-lib requires both status and control mmaps to be * coupled, we have to disable the status mmap for old alsa-lib, too. @@ -3667,11 +3668,19 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) offset = area->vm_pgoff << PAGE_SHIFT; switch (offset) { - case SNDRV_PCM_MMAP_OFFSET_STATUS: + case SNDRV_PCM_MMAP_OFFSET_STATUS_OLD: + if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) + return -ENXIO; + /* fallthrough */ + case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: if (!pcm_status_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_status(substream, file, area); - case SNDRV_PCM_MMAP_OFFSET_CONTROL: + case SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD: + if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) + return -ENXIO; + /* fallthrough */ + case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: if (!pcm_control_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_control(substream, file, area); @@ -3831,9 +3840,9 @@ static unsigned long snd_pcm_get_unmapped_area(struct file *file, unsigned long offset = pgoff << PAGE_SHIFT; switch (offset) { - case SNDRV_PCM_MMAP_OFFSET_STATUS: + case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: return (unsigned long)runtime->status; - case SNDRV_PCM_MMAP_OFFSET_CONTROL: + case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: return (unsigned long)runtime->control; default: return (unsigned long)runtime->dma_area + offset;