From patchwork Thu Nov 2 11:06:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117775 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1917720edm; Thu, 2 Nov 2017 04:08:12 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RGY3FA0M+pye8TGZwcgV57ysyc+PJnQwbKG/CfkgJUdZhA0KsGAchZ4FHL/hICjCQMie53 X-Received: by 10.101.68.69 with SMTP id e5mr3127103pgq.282.1509620891900; Thu, 02 Nov 2017 04:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620891; cv=none; d=google.com; s=arc-20160816; b=cRir35GYvixLGtW6BH/Sl5F6n2x1dSJXmIG7l1WZILCT7962VdAfrkzIxhvOXOBf9B MUzpXLeHOdA/fyUJ+iw0wAetKULvAiuY/FRK6lbNUVHnDp24OHzCmavvg77EZCAbq7g+ xQ9L5NUzciXwg57M5npu02jl97q9EBvooCfiJJaDQKgjDBYhbSwkcv+4umw0KaSVWAjN H8PJ3pxAtdm/uc9+Kn0W6KlsVXVdhDVi3iSg4NwupGjo4OcR5oB8c/DB50/3IYh25YF3 f9YQM7yoyWLDLQY7uvrqnBXP0mYgKRrIUyeb5jsbjxWYA3Dji1/03p6pMTVZKSclTx3f 8Tuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ZyDU73b31oe8ySM9Vo4fOM/+e3BZqc3fBmCQMwjTxx4=; b=TcBDdxquXJ47LCJPMsbWc/sMAzOQdLkfrJaFE6LN6Ms/zJbPOd/sZFWPK/yUcAYmFZ FvmYOEYSLkthMSlzdKLXWIfu55FEQJ3ZjpXc37RcSivlp5TbydznFKqRGO/Q3vT3LOFk zf3Xl+xeghg2VIZYtC9Twqrac4kZv4WlMv6cjGkXTeiYBm7wohLITziosVzCjW7nwB4z 8+LtQ4G2fKB8P4oAbvxit2NtSs6SdCitwrpUxMWd4Cio4LWYHY0PRNJzv2wv/HV/GjNE CkLOj4GNmotXNIAssXOUt2V7u5Y64DGKmdG2guUdYhvee3xtzaWaqwvgeTIbdM1npn55 ADUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BT51qpvr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34si1836829plz.343.2017.11.02.04.08.11; Thu, 02 Nov 2017 04:08:11 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=BT51qpvr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755625AbdKBLIJ (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:09 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:46341 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755549AbdKBLIG (ORCPT ); Thu, 2 Nov 2017 07:08:06 -0400 Received: by mail-pf0-f193.google.com with SMTP id p87so4339004pfj.3 for ; Thu, 02 Nov 2017 04:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ZyDU73b31oe8ySM9Vo4fOM/+e3BZqc3fBmCQMwjTxx4=; b=BT51qpvrux7JxCjIFtcAjVq1tfkh199kY3LuOz+rnluRsZZYz6mGRd1bjE8CINfGWA vn+TwHqpdq3xnce7DxE0ktw4pD1Rv6/Fh2VZsbDbqjvKNTKByK9Ziv/fichEh6aGMIDA P5UGxoRbcvwzFXNm4QOKvHf5F6vxKD55q7k8w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ZyDU73b31oe8ySM9Vo4fOM/+e3BZqc3fBmCQMwjTxx4=; b=uHHG1Z1UDOUljrlcO2oblC5xw+YzMIrWO2MClmMS5/+rZrX962+s/CqVywa+sWVpNL zHOHZePdrh5//2HLsbRUuOdlijBLBpSO8g2WbNaGrwQmxd4Qt/Kg+KKKqb2kN56vZNu0 Uv23uzCu/TEva+5IWqd/BcBvH9hHk2UV2K+Zn+rr9vxCaQ+Ch8MwbopU/Bmf53PUVFH1 pzQAjBXVuKEWfcBuCINg3DvdHL/1/nkGMqB3mmsZcexgD9Z9KrfdAHxPRClpQLzEtain b8S8rJ6dmEIVkk3uXdEQzmigOow3IHJyHQsv3vc85MhzV0j0q/KfzVaIeldlAJlCtpEa +I2w== X-Gm-Message-State: AMCzsaXRdMoPHqrpMJhBsMHX/ebQGO2QUQh8RBOZt/PVOCO7jDVpSKfu 7A7huZdeFenfJkx2zGSULmYIcw== X-Received: by 10.99.114.81 with SMTP id c17mr3190308pgn.43.1509620885493; Thu, 02 Nov 2017 04:08:05 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.00 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:04 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 1/7] sound: Replace timespec with timespec64 Date: Thu, 2 Nov 2017 19:06:51 +0800 Message-Id: <5ebd5e37e8f1bf2675996cf56538179b743bc95b.1509612175.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/sound/pcm.h | 18 +++++++++--------- include/sound/timer.h | 4 ++-- sound/core/pcm_lib.c | 30 +++++++++++++++++------------- 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, 57 insertions(+), 49 deletions(-) -- 1.7.9.5 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 24febf9..cd1ecd6 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -75,7 +75,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, @@ -343,7 +343,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; @@ -419,7 +419,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 -- */ @@ -1167,22 +1167,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); + getrawmonotonic64(tv); break; default: - getnstimeofday(tv); + ktime_get_real_ts64(tv); break; } } diff --git a/include/sound/timer.h b/include/sound/timer.h index c4d76ff..c196c07 100644 --- a/include/sound/timer.h +++ b/include/sound/timer.h @@ -102,7 +102,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; @@ -126,7 +126,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 a93a423..5ca9dc3 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -158,8 +158,12 @@ static void 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]; @@ -217,12 +221,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; @@ -246,16 +250,16 @@ 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); } - runtime->status->audio_tstamp = *audio_tstamp; - runtime->status->tstamp = *curr_tstamp; + 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; } @@ -268,8 +272,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; @@ -292,9 +296,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 2fec2fe..60bc303 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -881,12 +881,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) @@ -899,8 +899,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 6cdd04a..f44d702 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -73,7 +73,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; @@ -408,12 +408,12 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event) struct snd_timer *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; @@ -957,7 +957,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; @@ -1251,7 +1251,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; @@ -1265,7 +1265,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); @@ -1288,7 +1288,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)); @@ -1301,14 +1301,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; @@ -1322,14 +1322,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++; @@ -1808,7 +1808,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 d1eb148..c3e4516 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -502,7 +502,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) { @@ -522,7 +522,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 */ @@ -539,16 +539,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 2b1e513..9f905c4 100644 --- a/sound/soc/intel/skylake/skl-pcm.c +++ b/sound/soc/intel/skylake/skl-pcm.c @@ -1141,7 +1141,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) { @@ -1159,7 +1159,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 Thu Nov 2 11:06:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117776 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1917838edm; Thu, 2 Nov 2017 04:08:18 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Q8QHrYTfnP/CmOzZKZYBO2UmTIoiUj1hA2xknAVNKIbPDTSTe7z0bZPeNNdQNCzqmWfd0d X-Received: by 10.99.123.78 with SMTP id k14mr3140349pgn.351.1509620898473; Thu, 02 Nov 2017 04:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620898; cv=none; d=google.com; s=arc-20160816; b=oLoaEIFQ7Wv4DiR5qddn2KTum3L/NU6NCGfk3JDudnsm+pESChYCvgLziyzrnDy8b8 dTUuKs2wwSEJw71ULraq6HQPxwraTMoUVhO+hzV4sNKqwhQ+dARPx4Ko1D96ILO+kl/p CAw4qIJ0v6ypGd2Rjn6W3MwmqAykVASvpKKhHcUtKqOSSViwvovOEJRCEmI02BXeapgL MAKUrIUurOrDC+BcCg+uEXRGP6Tl/Y6wDMIGZovrajwgPqIdZd+lIx4VcPQpjq8No0CM J1IPEJZDBrDafHmWcjXaIX5gCIoQ6QlC4ifYLxI08yawGxY+I3cSE2JfJkjFQRREIIYY Nn6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=RiU1uTAwN58DJKVYBSB1nATwzjCuxY8snUReLPG3iVs=; b=QlToIGna5c4EudcHutZkxNn/HYzDD1to2hiGz1hWdoL2TsHPfXmiA9PxOvHtTLaKnk 0MQl8k1HPVoEvSNPSUmR9bwXIX+j/CprgmTx4LM53QNSRK9jJZv/gFeVZw/+G/g8VU54 09j+HESCNcKaQMG2Cvgh7u9jFGJ2RMi0/6RND1HjJPU4f9VunWwZQ5E/7DpXOzSp/oNZ bdHhXn4uWBkk6wOoMjd6oqpvDu8rWSO4OvzTJ2ezGXW9q0xfeW7gAIOzHhX89d3Itk1F 1i16Dn8k2tax0wxFH8aGJXzuApsx1/s8peVu6SQzjFRkG25G4wif3HNu8WL7uqc78wDZ IDsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KRTyhvrn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si3536959pff.367.2017.11.02.04.08.18; Thu, 02 Nov 2017 04:08:18 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=KRTyhvrn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755658AbdKBLIQ (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:16 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45088 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755626AbdKBLIM (ORCPT ); Thu, 2 Nov 2017 07:08:12 -0400 Received: by mail-pf0-f193.google.com with SMTP id d28so4344755pfe.2 for ; Thu, 02 Nov 2017 04:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=RiU1uTAwN58DJKVYBSB1nATwzjCuxY8snUReLPG3iVs=; b=KRTyhvrnSFc9TR/Z++5XpEHZ2I0AGWE5SFc0FNHRHpUCVS1VUMyvs/ulCLurJ1iZGc c7Gj5WR2H/N/PaaQV6Pn8oVDHeJVdvVvZdnQb+psadaWZ0oYVu55XCQTlCGMthn9LsPt F8HUK/DBoGaPV07WjAeQb+2N9Io7p4zDLh5FI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=RiU1uTAwN58DJKVYBSB1nATwzjCuxY8snUReLPG3iVs=; b=jdIEBDcGGh+B1MxBtM5Iu4tqpBW1fm5kKI4IbXHxrypV4Ri38qgjGAhsnEfpWbsFiH PZZe+nhidIYMp2kwBXrAE9+Ne+ZEp909uKNsVgK9jhg05Y8TimIsXQOXcGM+JL6lkm8G z64zKacVCqOqBYXxhuJoUIoQzQAehhqySy62+FeHObb4Fc/o82b0QGv2sdn4a0pwxsro GjcyaH0JItatInZ1Xf3kxAzQUuCRfw3YtbY1yYL9P9yEoGbz+7Cmoo2ox+XtROiv4w/h ZDAaXq+jLSMOE3fnSX4jLFTXV0qLviG1sTnIlspbZYogMe9YcgTAOz3O5EJ62OggGdyz Avgg== X-Gm-Message-State: AMCzsaVySlPpCCiX+Vtj+qKBYvoAA6DdOX6YeG0QSwV7lTHksWAGSjv/ Gx3olmUTHWIJuccoSZzGk0MuaA== X-Received: by 10.98.70.137 with SMTP id o9mr3365807pfi.19.1509620891109; Thu, 02 Nov 2017 04:08:11 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:10 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 2/7] sound: core: Avoid using timespec for struct snd_pcm_status Date: Thu, 2 Nov 2017 19:06:52 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 { ...... struct { s32 tv_sec; s32 tv_nsec; } trigger_tstamp; struct { s32 tv_sec; s32 tv_nsec; } tstamp; ...... } struct snd_pcm_status64 { ...... struct { s64 tv_sec; s64 tv_nsec; } trigger_tstamp; struct { s64 tv_sec; s64 tv_nsec; } tstamp; ...... } Moreover in compat file, we renamed or introduced new structures to handle 32bit/64bit time_t in compatible mode. 'struct compat_snd_pcm_status32' and snd_pcm_status_user_compat() 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 with 64bit alignment. 'struct compat_snd_pcm_status64_x86_32' and snd_pcm_status_user_compat64_x86_32() are used to handle 64bit time_t with 32bit alignment. 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 --- include/sound/pcm.h | 57 +++++++++++- sound/core/pcm.c | 12 +-- sound/core/pcm_compat.c | 236 +++++++++++++++++++++++++++++++++++------------ sound/core/pcm_native.c | 100 ++++++++++++++++---- 4 files changed, 319 insertions(+), 86 deletions(-) -- 1.7.9.5 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index cd1ecd6..7524b54 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -58,6 +58,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 */ @@ -565,8 +566,8 @@ struct snd_pcm_notify { 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); @@ -1440,4 +1441,56 @@ 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 */ + 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) + +#if __BITS_PER_LONG == 32 +struct snd_pcm_status32 { + snd_pcm_state_t 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; + 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 */ + 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 + #endif /* __SOUND_PCM_H */ diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 7eadb7f..c19e656 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -453,7 +453,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); @@ -463,17 +463,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 b719d0b..53b83d4 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -187,10 +187,12 @@ 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_status32 { s32 state; - struct compat_timespec trigger_tstamp; - struct compat_timespec tstamp; + s32 trigger_tstamp_sec; + s32 trigger_tstamp_nsec; + s32 tstamp_sec; + s32 tstamp_nsec; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -199,21 +201,25 @@ struct snd_pcm_status32 { u32 overrange; s32 suspended_state; u32 audio_tstamp_data; - struct compat_timespec audio_tstamp; - struct compat_timespec driver_tstamp; + s32 audio_tstamp_sec; + s32 audio_tstamp_nsec; + s32 driver_tstamp_sec; + s32 driver_tstamp_nsec; u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct compat_timespec)]; + unsigned char reserved[52-4*sizeof(s32)]; } __attribute__((packed)); static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, - struct snd_pcm_status32 __user *src, + struct compat_snd_pcm_status32 __user *src, bool ext) { - struct snd_pcm_status status; + struct snd_pcm_status64 status; + struct compat_snd_pcm_status32 compat_status32; int err; memset(&status, 0, sizeof(status)); + memset(&compat_status32, 0, sizeof(compat_status32)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, @@ -222,38 +228,47 @@ static int snd_pcm_status_user_compat(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) || - 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)) + + compat_status32 = (struct compat_snd_pcm_status32) { + .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_status32, sizeof(compat_status32))) return -EFAULT; return err; } -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_pcm_status_x32 { +struct compat_snd_pcm_status64 { s32 state; u32 rsvd; /* alignment */ - struct timespec trigger_tstamp; - struct timespec tstamp; + s64 trigger_tstamp_sec; + s64 trigger_tstamp_nsec; + s64 tstamp_sec; + s64 tstamp_nsec; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -262,22 +277,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, @@ -286,31 +305,116 @@ 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 */ + +#ifdef IA32_EMULATION +struct compat_snd_pcm_status64_x86_32 { + s32 state; + s64 trigger_tstamp_sec; + s64 trigger_tstamp_nsec; + s64 tstamp_sec; + s64 tstamp_nsec; + u32 appl_ptr; + u32 hw_ptr; + s32 delay; + u32 avail; + u32 avail_max; + u32 overrange; + s32 suspended_state; + u32 audio_tstamp_data; + s64 audio_tstamp_sec; + s64 audio_tstamp_nsec; + s64 driver_tstamp_sec; + s64 driver_tstamp_nsec; + u32 audio_tstamp_accuracy; + unsigned char reserved[52-4*sizeof(s64)]; +} __packed; + +static int +snd_pcm_status_user_compat64_x86_32(struct snd_pcm_substream *substream, + struct compat_snd_pcm_status64_x86_32 __user *src, + bool ext) +{ + struct snd_pcm_status64 status; + struct compat_snd_pcm_status64_x86_32 status_x86_32; + int err; + + memset(&status, 0, sizeof(status)); + memset(&status_x86_32, 0, sizeof(status_x86_32)); + /* + * 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_status64(substream, &status); + if (err < 0) + return err; + + if (clear_user(src, sizeof(*src))) + return -EFAULT; + + status_x86_32 = (struct compat_snd_pcm_status64_x86_32) { + .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, &status_x86_32, sizeof(status_x86_32))) + return -EFAULT; + + return err; +} +#endif /* both for HW_PARAMS and HW_REFINE */ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream, @@ -633,8 +737,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 compat_snd_pcm_status32), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct compat_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), @@ -644,10 +748,14 @@ 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 IA32_EMULATION + SNDRV_PCM_IOCTL_STATUS_COMPAT64_X86_32 = _IOR('A', 0x20, struct compat_snd_pcm_status64_x86_32), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64_X86_32 = _IOWR('A', 0x24, struct compat_snd_pcm_status64_x86_32), +#endif #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 */ }; @@ -697,9 +805,9 @@ 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: + case SNDRV_PCM_IOCTL_STATUS_COMPAT32: return snd_pcm_status_user_compat(substream, argp, false); - case SNDRV_PCM_IOCTL_STATUS_EXT32: + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: return snd_pcm_status_user_compat(substream, argp, true); case SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_ioctl_sync_ptr_compat(substream, argp); @@ -719,11 +827,17 @@ 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 IA32_EMULATION + case SNDRV_PCM_IOCTL_STATUS_COMPAT64_X86_32: + return snd_pcm_status_user_compat64_x86_32(substream, argp, false); + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64_X86_32: + return snd_pcm_status_user_compat64_x86_32(substream, argp, true); +#endif #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 60bc303..7a70848 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -854,8 +854,8 @@ static int snd_pcm_sw_params_user(struct snd_pcm_substream *substream, return err; } -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; @@ -881,14 +881,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, @@ -903,7 +911,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: @@ -933,11 +942,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)); @@ -949,7 +958,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))) @@ -957,6 +966,57 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream, return 0; } +#if __BITS_PER_LONG == 32 +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; +} +#endif + static int snd_pcm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info * info) { @@ -2888,10 +2948,16 @@ 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); +#if __BITS_PER_LONG == 32 + 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); +#endif + 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 Thu Nov 2 11:06:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117777 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1917906edm; Thu, 2 Nov 2017 04:08:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RqrtEUJlhJwgwXrveRgJE7NRFTu6M8BmaFbk7xRhPyVxj0fSe9UV3KM1/txKpLwz8kcy66 X-Received: by 10.98.17.156 with SMTP id 28mr3347619pfr.80.1509620901661; Thu, 02 Nov 2017 04:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620901; cv=none; d=google.com; s=arc-20160816; b=zTk3POg/6JxAyqZUktQANN5HmOfa6rsBdoM2NPB/fjP9eC8JMZODiQTwXooTTtZ0mT Mo962jokmzwHB1yIjkxtry/Peiiz8zHF7t9fTcn+7BXvhnF9G8YDmfQZzzBBABeqrpic oBZDoffUj48qmguqS2GUKjJ7kyeHgEwhYWkIEAbMXwFuwwWuf84mqlNwQE5jjNxTfyO4 3+dxGDK4jD533skFpZKah7aGQWT1vVY0MR09ZWaElU1B5QKO+9lQ7dkJ+RTzk3SWqjDo 0m7uSAFxoOSFgSXZmKiLEJ2NShbgOxwIiZR9wZsEJUjw3JzVtR/e0VFxOhS8ApwEe3S9 QgCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=UtK0B0foQNsfHd+nXlPZOq39fUsWHpl7m3knx0LoNJ0=; b=Q4ADezeSQRGEYD4MwNKedQDv7j+IABFbV5vdYNpiWb3fdrLgHwj6K9aTk/AyFWAlaZ oAGAs4f0GAntqwyck4iViP9vhF4HUg0wudzRzpAtfY3d+HC4m/YZ3Rywgvg42CQz26e6 ITGpVlvLdwPO8flK0nIz9cOydZBk1OVSVnWKSrW8pV1caUAjVzTnPVhmTnUCPtZYD6ZH FhQxfalblvf0e6tNCt0bnlGBtNLDgT8FQw7RLOd2u0BLJ4wW5v+lydsNbYo3lGsd3iLp SbZn5g1ejeaUP6iTDGKv3Fa92rQ+Ck6vIJ/vcuejuKJUU0cayB/QdlZ23r4XKMwxR8BB TVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GYHZsS2Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p27si3434851pgd.44.2017.11.02.04.08.21; Thu, 02 Nov 2017 04:08:21 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=GYHZsS2Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755688AbdKBLIT (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:19 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:57258 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755655AbdKBLIQ (ORCPT ); Thu, 2 Nov 2017 07:08:16 -0400 Received: by mail-pf0-f195.google.com with SMTP id b85so4319357pfj.13 for ; Thu, 02 Nov 2017 04:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=UtK0B0foQNsfHd+nXlPZOq39fUsWHpl7m3knx0LoNJ0=; b=GYHZsS2YLfdjs/dcXj80n9xYbyPzTl+HLaqgSqt8/gSzdpD0dr0HsD3UoLCzqFbq5e fFD3kPv8CpNBYvQTn9Oc2GIXZ7AbYGEp/9JO7Isbp5kW+nOYiotqSEhG/WYdRqyPxKi+ XJXd9z5MbJ0MC6FNR15fmBqvyNZBTItoqBKww= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=UtK0B0foQNsfHd+nXlPZOq39fUsWHpl7m3knx0LoNJ0=; b=mvxexutgA9ZJecJp6gKUyj7rWYvouJQ04fJkVWJ9H4UkjTpDoJFXdi1GaSwqkUMCan 5EyuBJ1PWl1H/9aogTzBU7o6ab5uNlGwwAHPiiW4yl3FZyqBe8MuI5GYex+p1OgdqzvR h1FjVhB+2dNL7DlNZPOAueZfAzKVErxl6j5qLwPbN2Cph4AhN122yusneA2xJm2Ptbif K0jYo2+2Ayb+ccgLH7Siv62cTXXqNSjZ0SYtyWcVmCSLcQVD3Q2qxXbZrbuFaxHHypWj VWaWdLE0eimVax0fh/ddNo4oYAXu2lQzJuum32ap4YoqJjVaWMYYVzMMaqlfgP+tFaoU 8Qlw== X-Gm-Message-State: AMCzsaX9Hq9H7fFCaEQC+9c3tgVbNGgc0UAkMX6wx9zospe8d/XqFsly wV8McqWDUFnMmQzmQV7wR7kjNQ== X-Received: by 10.101.88.14 with SMTP id g14mr3228720pgr.412.1509620896363; Thu, 02 Nov 2017 04:08:16 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.11 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:15 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 3/7] sound: core: Avoid using timespec for struct snd_rawmidi_status Date: Thu, 2 Nov 2017 19:06:53 +0800 Message-Id: <4aa4f178fed669b1d2b26965f81e934ae456322a.1509612176.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 'struct compat_snd_rawmidi_status32' and snd_rawmidi_ioctl_status_compat() are used to handle 32bit time_t in compat mode. 'struct compat_snd_rawmidi_status64' and snd_rawmidi_ioctl_status_compat64() are used to handle 64bit time_t with 64bit alignment. 'struct compat_snd_rawmidi_status64_x86_32' and snd_rawmidi_ioctl_status_compat64_x86_32() are used to handle 64bit time_t with 32bit alignment. 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 --- sound/core/rawmidi.c | 81 ++++++++++++++++++++++++++--- sound/core/rawmidi_compat.c | 121 +++++++++++++++++++++++++++++++++---------- 2 files changed, 168 insertions(+), 34 deletions(-) -- 1.7.9.5 diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index b3b353d..af79009 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -63,6 +63,30 @@ #define rmidi_dbg(rmidi, fmt, args...) \ dev_dbg(&(rmidi)->dev, fmt, ##args) +#if __BITS_PER_LONG == 32 +struct snd_rawmidi_status32 { + int stream; + s32 tstamp_sec; /* Timestamp */ + s32 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_STATUS32 _IOWR('W', 0x20, struct snd_rawmidi_status32) +#endif + +struct snd_rawmidi_status64 { + int stream; + 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; @@ -680,7 +704,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; @@ -693,7 +717,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; @@ -751,11 +775,55 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long return -EINVAL; } } - case SNDRV_RAWMIDI_IOCTL_STATUS: +#if __BITS_PER_LONG == 32 + case SNDRV_RAWMIDI_IOCTL_STATUS32: + { + 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; + } +#endif + case SNDRV_RAWMIDI_IOCTL_STATUS64: { int err = 0; - struct snd_rawmidi_status status; - if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status))) + 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: @@ -773,7 +841,8 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long } if (err < 0) return err; - if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status))) + if (copy_to_user(argp, &status, + sizeof(struct snd_rawmidi_status64))) return -EFAULT; return 0; } diff --git a/sound/core/rawmidi_compat.c b/sound/core/rawmidi_compat.c index f69764d..5b5b5ea 100644 --- a/sound/core/rawmidi_compat.c +++ b/sound/core/rawmidi_compat.c @@ -53,19 +53,21 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, return -EINVAL; } -struct snd_rawmidi_status32 { +struct compat_snd_rawmidi_status32 { s32 stream; - struct compat_timespec tstamp; + s32 tstamp_sec; + s32 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) + struct compat_snd_rawmidi_status32 __user *src) { int err; - struct snd_rawmidi_status status; + struct snd_rawmidi_status64 status; + struct compat_snd_rawmidi_status32 compat_status; if (rfile->output == NULL) return -EINVAL; @@ -85,32 +87,86 @@ 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)) + compat_status = (struct compat_snd_rawmidi_status32) { + .stream = status.stream, + .tstamp_sec = status.tstamp_sec, + .tstamp_nsec = status.tstamp_nsec, + .avail = status.avail, + .xruns = status.xruns, + }; + + if (copy_to_user(src, &compat_status, sizeof(*src))) return -EFAULT; return 0; } -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_rawmidi_status_x32 { +struct compat_snd_rawmidi_status64 { s32 stream; u32 rsvd; /* alignment */ - struct timespec tstamp; + s64 tstamp_sec; + s64 tstamp_nsec; 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_compat64(struct snd_rawmidi_file *rfile, + struct compat_snd_rawmidi_status64 __user *src) +{ + int err; + struct snd_rawmidi_status64 status; + struct compat_snd_rawmidi_status64 compat_status; + + if (rfile->output == NULL) + return -EINVAL; + if (get_user(status.stream, &src->stream)) + return -EFAULT; + + switch (status.stream) { + case SNDRV_RAWMIDI_STREAM_OUTPUT: + err = snd_rawmidi_output_status(rfile->output, &status); + break; + case SNDRV_RAWMIDI_STREAM_INPUT: + 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, + }; -static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, - struct snd_rawmidi_status_x32 __user *src) + if (copy_to_user(src, &compat_status, sizeof(*src))) + return -EFAULT; + + return 0; +} + +#ifdef IA32_EMULATION +struct compat_snd_rawmidi_status64_x86_32 { + s32 stream; + s64 tstamp_sec; + s64 tstamp_nsec; + u32 avail; + u32 xruns; + unsigned char reserved[16]; +} __attribute__((packed)); + +static int +snd_rawmidi_ioctl_status_compat64_x86_32(struct snd_rawmidi_file *rfile, + struct compat_snd_rawmidi_status64_x86_32 __user *src) { int err; - struct snd_rawmidi_status status; + struct snd_rawmidi_status64 status; + struct compat_snd_rawmidi_status64_x86_32 compat_status; if (rfile->output == NULL) return -EINVAL; @@ -130,21 +186,28 @@ static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, if (err < 0) return err; - if (put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.avail, &src->avail) || - put_user(status.xruns, &src->xruns)) + compat_status = (struct compat_snd_rawmidi_status64_x86_32) { + .stream = status.stream, + .tstamp_sec = status.tstamp_sec, + .tstamp_nsec = status.tstamp_nsec, + .avail = status.avail, + .xruns = status.xruns, + }; + + if (copy_to_user(src, &compat_status, sizeof(*src))) return -EFAULT; return 0; } -#endif /* CONFIG_X86_X32 */ +#endif 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 compat_snd_rawmidi_status32), + SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64), +#ifdef IA32_EMULATION + SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64_X86_32 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64_x86_32), +#endif }; static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -161,12 +224,14 @@ 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: + case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32: 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_COMPAT64: + return snd_rawmidi_ioctl_status_compat64(rfile, argp); +#ifdef IA32_EMULATION + case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64_X86_32: + return snd_rawmidi_ioctl_status_compat64_x86_32(rfile, argp); +#endif } return -ENOIOCTLCMD; } From patchwork Thu Nov 2 11:06:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117778 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1918002edm; Thu, 2 Nov 2017 04:08:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SWLCiWhLzN0fU7hRZLbWnnI8htQha3vb0MUBzl0Nq4oStaNlOIfabPej2DXOgxYdEGiuJz X-Received: by 10.84.184.12 with SMTP id l12mr2848469plc.404.1509620908148; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620908; cv=none; d=google.com; s=arc-20160816; b=bg8meL7YCbD+7tmpfiOcmcMnma6SAGs08M0d0xEqNBfWIXkUk0i7sjPiVkaatPZrUK 1oho1U6DIJFoGZMQMPqnE407vrRrOtz+P8D8KOgEoFZAQYmexW5zD7+/9gfznQF/tWMQ MLn1d++3gzZk4Zao0CwgPGMtXeI5YADI3khszH95yrPTxl2nVTpedzVf8DbkDw+C+wKa 5wlwjEb/moLnNb2EoZr7iz4t/zbjori0ypFMYFoCHPdDdQd1Go2BBEdCXBKCqvVMTsPR z/IEarwnnb+o0cb2l6WxjPkwF2+jDTVU2FUsk/DNmYVCHEB0PySI+ym8NGv6/OnZrdok sTfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=LJs32wpuJg/C0eOk56Mfa/bUF6QkN3VKWJsR9lsJHvRvvMe5oSi7TMd7WpF17ZXa7T qsNvH9H49kbum/dQydbjqNwutReZUr3AW+qq6sTP05/BOiQO02ILKJjYV6vRscpzZQiI w5nBeiaive/RRI78YmF4xvpFk3ABiuCy/RV6fBKcHkvbQlR6u5HiRA5KJNnylLI//cYq 3I/y588M07gfKSJHzmxeZcm37/boIeoYCLcL+/tpTl4RqfxFFvF3rwn9STtBuLeF78yQ xfrE/BPre7yBBjyrWvwVGoQIsoBOHlqOhh2EzDGzLpHeaXjTZQnrilXISiEmJJdweRDl ZR7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B5UT9FLM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si3503031pfh.332.2017.11.02.04.08.27; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=B5UT9FLM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755718AbdKBLI0 (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:26 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:50164 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755564AbdKBLIX (ORCPT ); Thu, 2 Nov 2017 07:08:23 -0400 Received: by mail-pg0-f65.google.com with SMTP id g6so4773877pgn.6 for ; Thu, 02 Nov 2017 04:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=B5UT9FLM14PbEHnyJCpoY2tLj6isYuPA2zGpu5DE8ZNdEijdCnVAQ6h4HatDBxfot0 sFYHGWJ7JC0Hh3S3VzT1sMmkKgpM/8u+8JONBMJpqxd1aXbZ0P29AtlX3wK2bi1VkVSE YLBAHCfnlB9gtw4eOQAbz4P3AVS0CQ0s1adPY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=Xl2dLTAWeSqT0WwEal6mmaYiwYR+R6eWnHq2g72VFq4M0damj/hOQdr/d8DFsozjkk sgqpjFySSB9v6rtge4/dUhOZ/FisjcM/mRvnWLWRmpLxe8ZE/R+hn3KKRfVPXNZ7sQfD N9VdXyJnjtHWiUY7lJy/Bm4u/3QcdOzcSVDm3qE8DndFxvtlNdEqSqgcgfUYoejn3zxp 0+PlfH4REPI+qOdexgmKC1smSpR9tH5GBkepOcfw7oe20ZU81e2CwYwYrY0TQEwjqFtB pLHC/tbVoazi5S/4RgsGOmOLfY8CjqjAOigR/AVvTEn8csOkxrbqB5Kb/OIEjDz2ZywG 5kzg== X-Gm-Message-State: AMCzsaWiX8+ze3t1KJh9v8o+TdJaDRzBf0MWuOXn7FNGDXkpIgktk3Pj Yn6Hfp3fTUg67tWaa9AKDo8Nzg== X-Received: by 10.99.120.7 with SMTP id t7mr3088755pgc.360.1509620902680; Thu, 02 Nov 2017 04:08:22 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:22 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 4/7] sound: core: Avoid using timespec for struct snd_timer_status Date: Thu, 2 Nov 2017 19:06:54 +0800 Message-Id: <9902c3c02cccba879bc9b8359b4af4aadfdcc5c1.1509612176.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The struct snd_timer_status will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Thus thia patch introduces 'struct snd_timer_status32' and 'struct snd_timer_status64' to handle 32bit time_t and 64bit time_t in native mode, which replace timespec with s64 type. In compat mode, this patch renamed the structure as 'struct compat_snd_timer_status32' to handle 32bit time_t. Moreover we should use 'struct snd_timer_status64' to handle 64bit time_t no matter 32bit or 64bit alignment, since they have the same size. 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 --- sound/core/timer.c | 62 ++++++++++++++++++++++++++++++++++++++++----- sound/core/timer_compat.c | 57 +++++------------------------------------ 2 files changed, 62 insertions(+), 57 deletions(-) -- 1.7.9.5 diff --git a/sound/core/timer.c b/sound/core/timer.c index f44d702..9168365 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -79,6 +79,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); @@ -1798,17 +1822,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; @@ -1920,8 +1968,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 6a437eb..3e09548 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -83,54 +83,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 (snd_BUG_ON(!tu->timeri)) - return -ENXIO; - 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, unsigned long arg) @@ -158,12 +115,10 @@ static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, uns 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 Thu Nov 2 11:06:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117779 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1918071edm; Thu, 2 Nov 2017 04:08:32 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QPl2hFV8VfUZMZVaH3oImJz2Y2+ysZfOOsXXInqXNMT1ZyKZtTOJW04izcwx7JAww+80Le X-Received: by 10.159.244.143 with SMTP id y15mr1924899plr.215.1509620912776; Thu, 02 Nov 2017 04:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620912; cv=none; d=google.com; s=arc-20160816; b=tWh90ZrLSodL5Dt+bDH2S36K5Ii43H6SGfUGSutLaKFHJjI7ugVn5jnhJwfjmhYqvo V2iQOKpiecTl+Ub4JOrjHTzQ/Fmmg3SN5WvJTFJq+z/rtntzNEt+aVmSFB8ZPNKWtNII Iooj6ULzDK9w48R0TpwI5tP3XQrdkmT76nD1q/pGTQtdztDvgnAXPznLlP63Nfg748bR EDlEFfaRcrCbwdmX4eV04Oh5rU8lnScf+Pu6apD2+jtvghQN5lhlVNVBiR7i8SyQZkDT jkXidx7omeYMZMhhh/pShBgbN3snDi2fgi6KMIn39VDZh4j9DLe0J54ZqrT9wi7k6Y0K 522A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=FR0uOs++al897k4uS7/SVwvx+ZSfjLWSJC8EJ8Pw5JA=; b=EaIA057iDWwtBxqYJlI4XDQyiBr/ieAdcSes5aK4j9rv470AiqDqPtJzVNnRRu9JI9 yIFLIdxDjHr5td+cRbtS0u3V0coFVnZ5EHnAnR3SlXDd/nD05nnsZoB/FVIa61SyCQNa kXvWw3rdqxzJ6gtl3qbt+iAHil9MyrkFlIp8rnR9c01nMmgllJu5+sccj5LvVwYNS3hU sheMMqmmLUzsOFfmH+8vdNGYG/7lg+ET3dBRJuMFUWiIaJbsuSFd8KQXXViC2jsblQ67 NYYz8pYBycr5uHPImYQUqczyLIFfDeHkmYAqJ7ZLbTqzcJH1EvkSqXPjklgXUf2cjKHG APGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RAP46s5J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si2153499ple.592.2017.11.02.04.08.32; Thu, 02 Nov 2017 04:08:32 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=RAP46s5J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755744AbdKBLIb (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:31 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43965 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755719AbdKBLI2 (ORCPT ); Thu, 2 Nov 2017 07:08:28 -0400 Received: by mail-pg0-f68.google.com with SMTP id s75so4788819pgs.0 for ; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FR0uOs++al897k4uS7/SVwvx+ZSfjLWSJC8EJ8Pw5JA=; b=RAP46s5JKO2KemLOBwLwpPsj/BwFA5UmC/1WaOpYDz7Z5pDq6d7Pebp02wO96Bo1vh Xntv+oeJ5YwATBPSu963XHBnerWtcdlqAMSiEApS/ld7kKINDz5Y/caoLjxQ4BtMBEDn SX5zFznSiPdoMgdz1gCE6Oxv1wZ7+qpDcP8Xg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FR0uOs++al897k4uS7/SVwvx+ZSfjLWSJC8EJ8Pw5JA=; b=NhsTf4Sl6wKUOeDSRIuYfenhRkaUgYIILgRDzBu7NGBY5LaiAk57Ixr5Kelm87VSLz NxzLWdLVWPkfflGjI5RsN9964zBt2j+BWkVpMfxysCMQkQcxLtX9MHBcDNspL4sTCl8R LPn3jib/Th7u197KzjUSkBIQNZ95VMaJBa7OpX+SzxHGm5NrpSWwNHTJGLwNcfyTZ6Vl g0fR0KGTZNF8BJs6ohQLCiiTq0xey3LzaEg0dyY3RdERw4qVcTN/ClJFSCLjVe+IAx2W U0x0vL1x8eUqs7l2YA30bIC4Uu/uEtWdZAG9L7wMrrWtFdNulNb538d5gBAZb1gh5YBQ 8nCQ== X-Gm-Message-State: AMCzsaXLoqKn4m53jsbT6mR+UTc2jZ3Jg904MeGT++sG1KR39uWUPs0n Koh36Ruz0dJuRWyQLXpd7ysSGg== X-Received: by 10.99.109.73 with SMTP id i70mr3080059pgc.177.1509620908326; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.22 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:27 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 5/7] uapi: sound: Avoid using timespec for struct snd_ctl_elem_value Date: Thu, 2 Nov 2017 19:06:55 +0800 Message-Id: <24089861471214ca49cf56e8a34a6304861cc170.1509612176.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thus we can simply change timespec to s64 for tstamp member to avoid using the type which is not year 2038 safe on 32bits system. Signed-off-by: Baolin Wang --- include/uapi/sound/asound.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 1.7.9.5 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 1949923..fabb283 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -943,8 +943,12 @@ struct snd_ctl_elem_value { } bytes; struct snd_aes_iec958 iec958; } value; /* RO */ - struct timespec tstamp; - unsigned char reserved[128-sizeof(struct timespec)]; +#ifndef __KERNEL__ + struct { s64 tv_sec; s64 tv_nsec; } tstamp; + unsigned char reserved[128-sizeof(struct { s64 tv_sec; s64 tv_nsec; })]; +#else + unsigned char reserved[128]; +#endif }; struct snd_ctl_tlv { From patchwork Thu Nov 2 11:06:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117780 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1918181edm; Thu, 2 Nov 2017 04:08:39 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SblGnFB3PD7flJbRC+HXH0miTUbHcqoU5n7yvKPJMiNtwtJhSW3rS3TscpEq/5GAR+5cH9 X-Received: by 10.101.80.200 with SMTP id s8mr3190305pgp.23.1509620919311; Thu, 02 Nov 2017 04:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620919; cv=none; d=google.com; s=arc-20160816; b=nBSg3+RHaWJfHhUYFsViyTb9+OyUBSHJ6wyBsMeL7OPI48PK4o3+seCiURVSPyAv6f E4XyCvcgVOGo2NX0ZxAKBj1l5vy1rr6xcJ1Vy9t1hVPD9cDB6hyYqH72jZc/dMoCvnTk qw5PxiNdKK6rXHgY5lIfL6Ouf7bIeMhHZaiiJPmIBYp5uhMB+dvnJKHMxj2rwxNZsfYa fqY2bGsj0bmBMyN79HUjHtDU2WwVYPWa+zptkrc9qvnKOSQDsBVWB6eMHqr1xguTCSYw 3X0JImRm9qE4HWK19eA4Zy7PWE4lrz4iStMpDyvdVxjUKtB5vW/asswJfNjFSwT2hA0W geVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=6sq7MWLAS4PMX9hoI+FgsHUN20Zcg1H2s0TfgMpPo1U=; b=VFbAO40xQ5eWqw2CEM0EIR3pti17352sJl8T1ntnSUysPd/iWp9De5D4UNAiLgHO4r FvCtpD6oTsdA5gUnnz99MQl8KsO4FxUqFh7Fnfk3+7Iy6lD+AcAFSsj/p/BHDx3wMc+s m8Y83mJx6xzNPxpVxHc9ES3ingJhurvVTm2VCZnRi8AOrae7/Gfn/LuaoSsxIEjU0xY7 9yq2Fa64JgWiKwJWmyKSsiQk8weq8UHeuCrFeXDIYpdjGFkGGoQfnVqQSPay0t7aSfQn HLs+/Hy8PKEWpKOqMcXJOvt2/I7Wxoq8SC6FCdaXEXx6D/i38Gj6RgbNRybPTZ4EvbPb N4rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gaPfwZuH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si3387452pgp.779.2017.11.02.04.08.39; Thu, 02 Nov 2017 04:08:39 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=gaPfwZuH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755765AbdKBLIi (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:38 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:48261 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755747AbdKBLIe (ORCPT ); Thu, 2 Nov 2017 07:08:34 -0400 Received: by mail-pg0-f68.google.com with SMTP id v78so4772603pgb.5 for ; Thu, 02 Nov 2017 04:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6sq7MWLAS4PMX9hoI+FgsHUN20Zcg1H2s0TfgMpPo1U=; b=gaPfwZuHCjtjGdXZjtp4eZDa30OXn7rsZNeF81AtvM7lHN9o8fg+ijMPzp+8PkUNg+ rpFVVUxkHkhWrArXUWpQMNtUBWsQtRiJZstdrxf/5DmF7fiJYa/cZEwc4CPS8Au7YGA4 QZ11Pyba6VpV9DHyGkK1Vc9S38yCS/Q6eETck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6sq7MWLAS4PMX9hoI+FgsHUN20Zcg1H2s0TfgMpPo1U=; b=dEShyZdSq4pRNiK8pUemY2AYJ6O2vb+BYAespudoXDVHgoyE50gKEtOJ6qpvMPtLyi n2+o4IWlJcMcA7paHlpx/12iBFZ+AIrphBZWSrBu9F1/kwVHgGSdtFN5UlD0cc50kyMC mMoze/tWjuuW4TUzLG0hwnydlXGKaCFdvC0BTiWeODgublK3uMroCd62DDe1JlM1g//k hi9xtNKWl7PdiCxqwL4K/X1vLnA9rgKvgl/hYi/5Afwb+rJXyiDYLPT1m9FIO3myCRVt U8ojCLm1SPnNKda0zG0ghPsbWlPTEyDgnfjn99WZc0La2nABtcc30GwmyAg6S5d2q4OZ HQkQ== X-Gm-Message-State: AMCzsaURAcKm41bPbXNZ4vq0avUPLjDYKdgkDTdplhb1z8HVDzm+Sqj5 tZzl4/gtT/4l4NIxUvpMzOZhgA== X-Received: by 10.101.66.65 with SMTP id d1mr3217841pgq.63.1509620913890; Thu, 02 Nov 2017 04:08:33 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.28 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:33 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 6/7] sound: core: Avoid using timespec for struct snd_pcm_sync_ptr Date: Thu, 2 Nov 2017 19:06:56 +0800 Message-Id: <090460a6a5c77d266ec119afbc216ff47ba62f38.1509612176.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The struct snd_pcm_sync_ptr will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Thus we introduced 'struct snd_pcm_sync_ptr32' and 'struct snd_pcm_sync_ptr64' 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 compat_snd_pcm_sync_ptr32' and snd_pcm_ioctl_sync_ptr_compat() are used to handle 32bit time_t in compat mode. 'struct compat_snd_pcm_sync_ptr64' and snd_pcm_ioctl_sync_ptr_compat64() are used to handle 64bit time_t with 64bit alignment. 'struct compat_snd_pcm_sync_ptr64_x86_32' and snd_pcm_ioctl_sync_ptr_compat64_x86_32() are used to handle 64bit time_t with 32bit alignment. When glibc changes time_t to 64bit, any recompiled program will issue ioctl commands that the kernel does not understand without this patch. Signed-off-by: Baolin Wang --- include/sound/pcm.h | 51 ++++++++++- sound/core/pcm.c | 8 +- sound/core/pcm_compat.c | 233 ++++++++++++++++++++++++++++++++++++----------- sound/core/pcm_lib.c | 9 +- sound/core/pcm_native.c | 122 +++++++++++++++++++------ 5 files changed, 336 insertions(+), 87 deletions(-) -- 1.7.9.5 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 7524b54..b23b4f5 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -64,6 +64,18 @@ struct snd_pcm_hardware { struct snd_pcm_audio_tstamp_config; /* definitions further down */ struct snd_pcm_audio_tstamp_report; +struct snd_pcm_mmap_status64 { + snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + int pad1; /* Needed for 64 bit alignment */ + u64 hw_ptr; /* RO: hw ptr (0...boundary-1) */ + s64 tstamp_sec; /* Timestamp */ + s64 tstamp_nsec; + snd_pcm_state_t suspended_state; /* RO: suspended stream state */ + u32 pad3; + s64 audio_tstamp_sec; /* from sample counter or wall clock */ + s64 audio_tstamp_nsec; +}; + struct snd_pcm_ops { int (*open)(struct snd_pcm_substream *substream); int (*close)(struct snd_pcm_substream *substream); @@ -389,7 +401,7 @@ struct snd_pcm_runtime { union snd_pcm_sync_id sync; /* hardware synchronization ID */ /* -- mmap -- */ - struct snd_pcm_mmap_status *status; + struct snd_pcm_mmap_status64 *status; struct snd_pcm_mmap_control *control; /* -- locking / scheduling -- */ @@ -1463,8 +1475,32 @@ struct snd_pcm_status64 { unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */ }; +struct snd_pcm_sync_ptr64 { + unsigned int flags; + union { + struct snd_pcm_mmap_status64 status; + unsigned char reserved[64]; + } s; + union { + struct snd_pcm_mmap_control control; + unsigned char reserved[64]; + } c; +}; + +struct snd_pcm_mmap_status32 { + snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + int pad1; /* Needed for 64 bit alignment */ + u32 hw_ptr; /* RO: hw ptr (0...boundary-1) */ + s32 tstamp_sec; /* Timestamp */ + s32 tstamp_nsec; + snd_pcm_state_t suspended_state; /* RO: suspended stream state */ + s32 audio_tstamp_sec; /* from sample counter or wall clock */ + s32 audio_tstamp_nsec; +}; + #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) +#define SNDRV_PCM_IOCTL_SYNC_PTR64 _IOWR('A', 0x23, struct snd_pcm_sync_ptr64) #if __BITS_PER_LONG == 32 struct snd_pcm_status32 { @@ -1489,8 +1525,21 @@ struct snd_pcm_status32 { unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */ }; +struct snd_pcm_sync_ptr32 { + unsigned int flags; + union { + struct snd_pcm_mmap_status32 status; + unsigned char reserved[64]; + } s; + union { + struct snd_pcm_mmap_control control; + unsigned char reserved[64]; + } c; +}; + #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) +#define SNDRV_PCM_IOCTL_SYNC_PTR32 _IOWR('A', 0x23, struct snd_pcm_sync_ptr32) #endif #endif /* __SOUND_PCM_H */ diff --git a/sound/core/pcm.c b/sound/core/pcm.c index c19e656..3c27e68 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -478,7 +478,7 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, snd_iprintf(buffer, "avail : %ld\n", status.avail); snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max); snd_iprintf(buffer, "-----\n"); - snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr); + snd_iprintf(buffer, "hw_ptr : %lld\n", runtime->status->hw_ptr); snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr); unlock: mutex_unlock(&substream->pcm->open_mutex); @@ -1001,7 +1001,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, if (runtime == NULL) return -ENOMEM; - size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)); + size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status64)); runtime->status = snd_malloc_pages(size, GFP_KERNEL); if (runtime->status == NULL) { kfree(runtime); @@ -1013,7 +1013,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, runtime->control = snd_malloc_pages(size, GFP_KERNEL); if (runtime->control == NULL) { snd_free_pages((void*)runtime->status, - PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status64))); kfree(runtime); return -ENOMEM; } @@ -1044,7 +1044,7 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) if (runtime->private_free != NULL) runtime->private_free(runtime); snd_free_pages((void*)runtime->status, - PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status64))); snd_free_pages((void*)runtime->control, PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); kfree(runtime->hw_constraints.rules); diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index 53b83d4..885aefb 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -557,42 +557,33 @@ 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 { +struct compat_snd_pcm_mmap_control32 { u32 appl_ptr; u32 avail_min; }; -struct snd_pcm_sync_ptr32 { +struct compat_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; + struct compat_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 compat_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_status64 *status; volatile struct snd_pcm_mmap_control *control; u32 sflags; struct snd_pcm_mmap_control scontrol; - struct snd_pcm_mmap_status sstatus; + struct snd_pcm_mmap_status64 sstatus; + struct compat_snd_pcm_sync_ptr32 sync_ptr; snd_pcm_uframes_t boundary; int err; @@ -625,63 +616,76 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, scontrol.avail_min = control->avail_min; sstatus.state = status->state; sstatus.hw_ptr = status->hw_ptr % boundary; - sstatus.tstamp = status->tstamp; + sstatus.tstamp_sec = status->tstamp_sec; + sstatus.tstamp_nsec = status->tstamp_nsec; sstatus.suspended_state = status->suspended_state; - sstatus.audio_tstamp = status->audio_tstamp; + sstatus.audio_tstamp_sec = status->audio_tstamp_sec; + sstatus.audio_tstamp_nsec = status->audio_tstamp_nsec; 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)) + + memset(&sync_ptr, 0, sizeof(sync_ptr)); + sync_ptr.s.status = (struct snd_pcm_mmap_status32) { + .state = sstatus.state, + .hw_ptr = sstatus.hw_ptr, + .tstamp_sec = sstatus.tstamp_sec, + .tstamp_nsec = sstatus.tstamp_nsec, + .suspended_state = sstatus.suspended_state, + .audio_tstamp_sec = sstatus.audio_tstamp_sec, + .audio_tstamp_nsec = sstatus.audio_tstamp_nsec, + }; + + sync_ptr.c.control = (struct compat_snd_pcm_mmap_control32) { + .appl_ptr = scontrol.appl_ptr, + .avail_min = scontrol.avail_min, + }; + + if (copy_to_user(src, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; return 0; } -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_pcm_mmap_status_x32 { +struct compat_snd_pcm_mmap_status64 { s32 state; 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 { +struct compat_snd_pcm_mmap_control64 { u32 appl_ptr; u32 avail_min; }; -struct snd_pcm_sync_ptr_x32 { +struct compat_snd_pcm_sync_ptr64 { u32 flags; u32 rsvd; /* alignment */ union { - struct snd_pcm_mmap_status_x32 status; + struct compat_snd_pcm_mmap_status64 status; unsigned char reserved[64]; } s; union { - struct snd_pcm_mmap_control_x32 control; + struct compat_snd_pcm_mmap_control64 control; unsigned char reserved[64]; } c; } __packed; -static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream, - struct snd_pcm_sync_ptr_x32 __user *src) +static int snd_pcm_ioctl_sync_ptr_compat64(struct snd_pcm_substream *substream, + struct compat_snd_pcm_sync_ptr64 __user *src) { struct snd_pcm_runtime *runtime = substream->runtime; - volatile struct snd_pcm_mmap_status *status; + volatile struct snd_pcm_mmap_status64 *status; volatile struct snd_pcm_mmap_control *control; u32 sflags; struct snd_pcm_mmap_control scontrol; - struct snd_pcm_mmap_status sstatus; + struct snd_pcm_mmap_status64 sstatus; + struct compat_snd_pcm_sync_ptr64 sync_ptr; snd_pcm_uframes_t boundary; int err; @@ -714,22 +718,136 @@ static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream, scontrol.avail_min = control->avail_min; sstatus.state = status->state; sstatus.hw_ptr = status->hw_ptr % boundary; - sstatus.tstamp = status->tstamp; + sstatus.tstamp_sec = status->tstamp_sec; + sstatus.tstamp_nsec = status->tstamp_nsec; sstatus.suspended_state = status->suspended_state; - sstatus.audio_tstamp = status->audio_tstamp; + sstatus.audio_tstamp_sec = status->audio_tstamp_sec; + sstatus.audio_tstamp_nsec = status->audio_tstamp_nsec; 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.suspended_state, &src->s.status.suspended_state) || - 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)) + + memset(&sync_ptr, 0, sizeof(sync_ptr)); + sync_ptr.s.status = (struct compat_snd_pcm_mmap_status64) { + .state = sstatus.state, + .hw_ptr = sstatus.hw_ptr, + .tstamp_sec = sstatus.tstamp_sec, + .tstamp_nsec = sstatus.tstamp_nsec, + .suspended_state = sstatus.suspended_state, + .audio_tstamp_sec = sstatus.audio_tstamp_sec, + .audio_tstamp_nsec = sstatus.audio_tstamp_nsec, + }; + + sync_ptr.c.control = (struct compat_snd_pcm_mmap_control64) { + .appl_ptr = scontrol.appl_ptr, + .avail_min = scontrol.avail_min, + }; + + if (copy_to_user(src, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; return 0; } -#endif /* CONFIG_X86_X32 */ + +#ifdef IA32_EMULATION +struct compat_snd_pcm_mmap_status64_x86_32 { + s32 state; + s32 pad1; + u32 hw_ptr; + s64 tstamp_sec; + s64 tstamp_nsec; + s32 suspended_state; + s64 audio_tstamp_sec; + s64 audio_tstamp_nsec; +} __packed; + +struct compat_snd_pcm_mmap_control64_x86_32 { + u32 appl_ptr; + u32 avail_min; +}; + +struct compat_snd_pcm_sync_ptr64_x86_32 { + u32 flags; + union { + struct compat_snd_pcm_mmap_status64_x86_32 status; + unsigned char reserved[64]; + } s; + union { + struct compat_snd_pcm_mmap_control64_x86_32 control; + unsigned char reserved[64]; + } c; +} __packed; + +static int +snd_pcm_ioctl_sync_ptr_compat64_x86_32(struct snd_pcm_substream *substream, + struct compat_snd_pcm_sync_ptr64_x86_32 __user *src) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + volatile struct snd_pcm_mmap_status64 *status; + volatile struct snd_pcm_mmap_control *control; + u32 sflags; + struct snd_pcm_mmap_control scontrol; + struct snd_pcm_mmap_status64 sstatus; + struct compat_snd_pcm_sync_ptr64_x86_32 sync_ptr; + 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_sec = status->tstamp_sec; + sstatus.tstamp_nsec = status->tstamp_nsec; + sstatus.suspended_state = status->suspended_state; + sstatus.audio_tstamp_sec = status->audio_tstamp_sec; + sstatus.audio_tstamp_nsec = status->audio_tstamp_nsec; + snd_pcm_stream_unlock_irq(substream); + + memset(&sync_ptr, 0, sizeof(sync_ptr)); + sync_ptr.s.status = (struct compat_snd_pcm_mmap_status64_x86_32) { + .state = sstatus.state, + .hw_ptr = sstatus.hw_ptr, + .tstamp_sec = sstatus.tstamp_sec, + .tstamp_nsec = sstatus.tstamp_nsec, + .suspended_state = sstatus.suspended_state, + .audio_tstamp_sec = sstatus.audio_tstamp_sec, + .audio_tstamp_nsec = sstatus.audio_tstamp_nsec, + }; + + sync_ptr.c.control = (struct compat_snd_pcm_mmap_control64_x86_32) { + .appl_ptr = scontrol.appl_ptr, + .avail_min = scontrol.avail_min, + }; + + if (copy_to_user(src, &sync_ptr, sizeof(sync_ptr))) + return -EFAULT; + + return 0; +} +#endif /* */ @@ -747,12 +865,14 @@ 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_SYNC_PTR_COMPAT32 = _IOWR('A', 0x23, struct compat_snd_pcm_sync_ptr32), + SNDRV_PCM_IOCTL_SYNC_PTR_COMPAT64 = _IOWR('A', 0x23, struct compat_snd_pcm_sync_ptr64), 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 IA32_EMULATION SNDRV_PCM_IOCTL_STATUS_COMPAT64_X86_32 = _IOR('A', 0x20, struct compat_snd_pcm_status64_x86_32), SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64_X86_32 = _IOWR('A', 0x24, struct compat_snd_pcm_status64_x86_32), + SNDRV_PCM_IOCTL_SYNC_PTR_COMPAT64_X86_32 = _IOWR('A', 0x23, struct compat_snd_pcm_sync_ptr64_x86_32), #endif #ifdef CONFIG_X86_X32 SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info), @@ -809,8 +929,17 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_status_user_compat(substream, argp, false); case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: return snd_pcm_status_user_compat(substream, argp, true); - case SNDRV_PCM_IOCTL_SYNC_PTR32: - return snd_pcm_ioctl_sync_ptr_compat(substream, argp); + case SNDRV_PCM_IOCTL_SYNC_PTR_COMPAT32: + { + if (sizeof(__kernel_long_t) == sizeof(time_t)) + return snd_pcm_ioctl_sync_ptr_compat(substream, argp); +#ifdef IA32_EMULATION + else + return snd_pcm_ioctl_sync_ptr_compat64_x86_32(substream, argp); +#endif + } + case SNDRV_PCM_IOCTL_SYNC_PTR_COMPAT64: + return snd_pcm_ioctl_sync_ptr_compat64(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: return snd_pcm_ioctl_channel_info_compat(substream, argp); case SNDRV_PCM_IOCTL_WRITEI_FRAMES32: diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 5ca9dc3..f3e5d43 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -162,7 +162,8 @@ static void xrun(struct snd_pcm_substream *substream) struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); - runtime->status->tstamp = timespec64_to_timespec(tstamp); + runtime->status->tstamp_sec = tstamp.tv_sec; + runtime->status->tstamp_nsec = tstamp.tv_nsec; } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { @@ -252,8 +253,10 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, runtime->rate); *audio_tstamp = ns_to_timespec64(audio_nsecs); } - runtime->status->audio_tstamp = timespec64_to_timespec(*audio_tstamp); - runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); + runtime->status->audio_tstamp_sec = audio_tstamp->tv_sec; + runtime->status->audio_tstamp_nsec = audio_tstamp->tv_nsec; + runtime->status->tstamp_sec = curr_tstamp->tv_sec; + runtime->status->tstamp_nsec = curr_tstamp->tv_nsec; /* * re-take a driver timestamp to let apps detect if the reference tstamp diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 7a70848..6063522 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -886,17 +886,17 @@ int snd_pcm_status64(struct snd_pcm_substream *substream, if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { - status->tstamp_sec = runtime->status->tstamp.tv_sec; + status->tstamp_sec = runtime->status->tstamp_sec; status->tstamp_nsec = - runtime->status->tstamp.tv_nsec; + runtime->status->tstamp_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; + runtime->status->audio_tstamp_sec; status->audio_tstamp_nsec = - runtime->status->audio_tstamp.tv_nsec; + runtime->status->audio_tstamp_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, @@ -2766,50 +2766,109 @@ static snd_pcm_sframes_t snd_pcm_delay(struct snd_pcm_substream *substream) snd_pcm_stream_unlock_irq(substream); return err < 0 ? err : n; } - + static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, - struct snd_pcm_sync_ptr __user *_sync_ptr) + struct snd_pcm_sync_ptr64 *sync_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; - struct snd_pcm_sync_ptr sync_ptr; - volatile struct snd_pcm_mmap_status *status; + volatile struct snd_pcm_mmap_status64 *status; volatile struct snd_pcm_mmap_control *control; int err; - memset(&sync_ptr, 0, sizeof(sync_ptr)); - if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) - return -EFAULT; - if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control))) - return -EFAULT; status = runtime->status; control = runtime->control; - if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { + if (sync_ptr->flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } snd_pcm_stream_lock_irq(substream); - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { + if (!(sync_ptr->flags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, - sync_ptr.c.control.appl_ptr); + sync_ptr->c.control.appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else { - sync_ptr.c.control.appl_ptr = control->appl_ptr; + sync_ptr->c.control.appl_ptr = control->appl_ptr; } - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) - control->avail_min = sync_ptr.c.control.avail_min; + if (!(sync_ptr->flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) + control->avail_min = sync_ptr->c.control.avail_min; else - sync_ptr.c.control.avail_min = control->avail_min; - sync_ptr.s.status.state = status->state; - sync_ptr.s.status.hw_ptr = status->hw_ptr; - sync_ptr.s.status.tstamp = status->tstamp; - sync_ptr.s.status.suspended_state = status->suspended_state; + sync_ptr->c.control.avail_min = control->avail_min; + sync_ptr->s.status.state = status->state; + sync_ptr->s.status.hw_ptr = status->hw_ptr; + sync_ptr->s.status.tstamp_sec = status->tstamp_sec; + sync_ptr->s.status.tstamp_nsec = status->tstamp_nsec; + sync_ptr->s.status.suspended_state = status->suspended_state; snd_pcm_stream_unlock_irq(substream); + + return 0; +} + +#if __BITS_PER_LONG == 32 +static int snd_pcm_sync_ptr32(struct snd_pcm_substream *substream, + struct snd_pcm_sync_ptr32 __user *_sync_ptr) +{ + struct snd_pcm_sync_ptr64 sync_ptr64; + struct snd_pcm_sync_ptr32 sync_ptr32; + int ret; + + memset(&sync_ptr64, 0, sizeof(sync_ptr64)); + memset(&sync_ptr32, 0, sizeof(sync_ptr32)); + if (get_user(sync_ptr64.flags, (unsigned __user *)&(_sync_ptr->flags))) + return -EFAULT; + if (copy_from_user(&sync_ptr64.c.control, &(_sync_ptr->c.control), + sizeof(struct snd_pcm_mmap_control))) + return -EFAULT; + + ret = snd_pcm_sync_ptr(substream, &sync_ptr64); + if (ret) + return ret; + + sync_ptr32.s.status = (struct snd_pcm_mmap_status32) { + .state = sync_ptr64.s.status.state, + .hw_ptr = sync_ptr64.s.status.hw_ptr, + .tstamp_sec = sync_ptr64.s.status.tstamp_sec, + .tstamp_nsec = sync_ptr64.s.status.tstamp_nsec, + .suspended_state = sync_ptr64.s.status.suspended_state, + .audio_tstamp_sec = sync_ptr64.s.status.audio_tstamp_sec, + .audio_tstamp_nsec = sync_ptr64.s.status.audio_tstamp_nsec, + }; + + sync_ptr32.c.control = (struct snd_pcm_mmap_control) { + .appl_ptr = sync_ptr64.c.control.appl_ptr, + .avail_min = sync_ptr64.c.control.avail_min, + }; + + if (copy_to_user(_sync_ptr, &sync_ptr32, sizeof(sync_ptr32))) + return -EFAULT; + + return 0; +} +#endif + +static int snd_pcm_sync_ptr64(struct snd_pcm_substream *substream, + struct snd_pcm_sync_ptr64 __user *_sync_ptr) +{ + struct snd_pcm_sync_ptr64 sync_ptr; + int ret; + + memset(&sync_ptr, 0, sizeof(sync_ptr)); + if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) + return -EFAULT; + if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), + sizeof(struct snd_pcm_mmap_control))) + return -EFAULT; + + ret = snd_pcm_sync_ptr(substream, &sync_ptr); + if (ret) + return ret; + if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; + return 0; } @@ -2987,8 +3046,17 @@ static int snd_pcm_common_ioctl(struct file *file, return -EFAULT; return 0; } - case SNDRV_PCM_IOCTL_SYNC_PTR: - return snd_pcm_sync_ptr(substream, arg); + case SNDRV_PCM_IOCTL_SYNC_PTR64: + { +#if __BITS_PER_LONG == 64 + return snd_pcm_sync_ptr64(substream, arg); +#else + if (sizeof(__kernel_long_t) == sizeof(time_t)) + return snd_pcm_sync_ptr32(substream, arg); + else + return snd_pcm_sync_ptr64(substream, arg); +#endif + } #ifdef CONFIG_SND_SUPPORT_OLD_API case SNDRV_PCM_IOCTL_HW_REFINE_OLD: return snd_pcm_hw_refine_old_user(substream, arg); @@ -3321,7 +3389,7 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; - if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))) + if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status64))) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_status; area->vm_private_data = substream; From patchwork Thu Nov 2 11:06:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117781 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1918312edm; Thu, 2 Nov 2017 04:08:46 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RkzhhERonzz7WgZB9eabFsdx4K8uZOuVika4p5fCPIDTxO6d7+oM8Sg/Joqi8UMuAbMbS2 X-Received: by 10.98.201.138 with SMTP id l10mr3415831pfk.116.1509620926514; Thu, 02 Nov 2017 04:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620926; cv=none; d=google.com; s=arc-20160816; b=dElL5MCoIVu3iPakJhnh8MnJgXEb99JXWpq9b9IC021KlWJttQaa8579YAVd7iPzPh xo/ajMp9ITzo/Ea1FlvBXcc6iEXOM99QM3CLl7Fd2lFgYox1d8U5VVk8i0mKYqWoTmcY bfHeYkDFNBR0p/RciuaBQuVt4PjvLLvOECDu3LIHHXsFF2RuOKNmg/Jyshf2z+1+V+Da OEfttQM9oJF1mHb7/G6WcdqDJSyJXrEbYcDmSa+5QCfQYDepKSPn9aBj2hPSQi8eAz7l PfRo0WwPyP+yVQPUbQCpj7FpOSNtJJoCAbKxzy5ioj+yV2/gxRcYcXl6NsGl0Y1gww/a iuKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=jvr/ObOjweU78sOPxOd7HUOb4iyftvy9b5LgAkNqxQQ=; b=Sk9l5ZlAvcKGxT1ihEZeGOoYats+H2XTAcrWYGl+EqtNnCrhHBGlm4dxxOSnoklHwI eGlxSFvj7RjJqjc10Ojo87lsPOXIu1jZejqf2jPRWg29YcrztfArDsodY1qiPvFtGUc6 +m9j4jK3oeExjZbDkyHTVUzU6Vy/uKSstvr3xNdtGaSFeQ1fG5xmPpy0dsUNHBx3SVsh qByY/rP6uH4pIoHN2Y/lRpFTs9O7W7wdkIc8CHj8Ae9p8eA+/7/lM05ZjHBAIf7qlpUc ctCuOpMEtKWdOdnsj1Tx4c1nVlMr8PUMkYNlhcKF6osycaFbUrtWRCsmYSDhI9QQu3Q3 RBIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jBRWySy1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si3556867pfj.22.2017.11.02.04.08.46; Thu, 02 Nov 2017 04:08:46 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=jBRWySy1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755785AbdKBLIo (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:44 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:48277 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755766AbdKBLIk (ORCPT ); Thu, 2 Nov 2017 07:08:40 -0400 Received: by mail-pg0-f68.google.com with SMTP id v78so4772815pgb.5 for ; Thu, 02 Nov 2017 04:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jvr/ObOjweU78sOPxOd7HUOb4iyftvy9b5LgAkNqxQQ=; b=jBRWySy1uVeTiCkH3xG+Af5kLGbqBr1aMM2XqWcQZ7SYcGs0sCTU8r/V1LOB/GYMAa D4mFNldHXicZKPNJg+iY2ajWbs2okeE0nRT46wzzk1VNd68cEjmwtnpXNk83d6le55mG 1xRj4ZDHPAd/TIfimV2bdh7fJn1PZr8EH6qWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jvr/ObOjweU78sOPxOd7HUOb4iyftvy9b5LgAkNqxQQ=; b=hDQ58V4uWQs25aR35N2SoUl/ErIbIIEADDyl7WR92Du3lrAzOLWxle8KQ0kffaSDsN ytYwI/f3sLu15bIjrhY9ovkg1wGq3oBaoPgIOicv+FK+Ya+PzzRTt2OKU0h25iZvC0pG maHzWvKotQVIBC7sNPJLJXUz3iJjs9UXbx3wbn3wy+ZXOOu5f9iy9DjqfOMmlziP/U7W BQMD+tt/wYywMXMb1P1ZNWRgb1uoqwiItlmtn0pg582/IBQ3yRwgt21p3SFZO79FJ+HB nV6vJ20KjR+wfWhgy2iLAxCwMdNw8GSh0KScnGmR54+6bVwofQl5heuIan0oRUcq/tEq To7Q== X-Gm-Message-State: AMCzsaUWa4J31nwmCnTPEfc4b0dXkie6bumB0cX532WXSIcnzQOWS9/r V85/UmjeyIVa+X2UFXm2AnFM4Q== X-Received: by 10.159.253.9 with SMTP id p9mr2883074pls.323.1509620919580; Thu, 02 Nov 2017 04:08:39 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.34 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:39 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 7/7] sound: core: Avoid using timespec for struct snd_timer_tread Date: Thu, 2 Nov 2017 19:06:57 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Also add one struct compat_snd_timer_tread64_x86_32 to handle 64bit time_t with 32bit alignment. 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. For x86_32 mode, we will set tu->tread = TREAD_FORMAT_TIME32_X86 to copy struct compat_snd_timer_tread64_x86_32 for user. 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 --- include/uapi/sound/asound.h | 11 ++- sound/core/timer.c | 173 ++++++++++++++++++++++++++++++++++--------- sound/core/timer_compat.c | 10 ++- 3 files changed, 157 insertions(+), 37 deletions(-) -- 1.7.9.5 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index fabb283..4c74f52 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -760,7 +760,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) @@ -773,6 +773,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; diff --git a/sound/core/timer.c b/sound/core/timer.c index 9168365..ba6c09e 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -58,6 +58,30 @@ MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER); MODULE_ALIAS("devname:snd/timer"); +enum timer_tread_format { + TREAD_FORMAT_NONE = 0, + TREAD_FORMAT_64BIT, + TREAD_FORMAT_TIME64, + TREAD_FORMAT_TIME32_X86, + TREAD_FORMAT_TIME32, +}; + +struct snd_timer_tread64 { + int event; + u32 pad1; + s64 tstamp_sec; + s64 tstamp_nsec; + unsigned int val; + u32 pad2; +}; + +struct compat_snd_timer_tread64_x86_32 { + int event; + s64 tstamp_sec; + s64 tstamp_nsec; + unsigned int val; +} __packed; + struct snd_timer_user { struct snd_timer_instance *timeri; int tread; /* enhanced read with timestamps and events */ @@ -69,7 +93,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; @@ -1262,7 +1286,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++; @@ -1279,7 +1303,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 && @@ -1289,7 +1313,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); @@ -1311,7 +1336,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; @@ -1332,7 +1357,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; @@ -1346,14 +1372,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++; @@ -1368,7 +1396,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); @@ -1797,11 +1825,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 { @@ -1919,6 +1947,39 @@ static int snd_timer_user_pause(struct file *file) return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 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 (!IS_ENABLED(CONFIG_64BITS) && !compat) + tu->tread = TREAD_FORMAT_64BIT; + else if (cmd == SNDRV_TIMER_IOCTL_TREAD64) + tu->tread = TREAD_FORMAT_TIME64; + else if (IS_ENABLED(CONFIG_X86)) + tu->tread = TREAD_FORMAT_TIME32_X86; + 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), @@ -1927,7 +1988,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; @@ -1939,23 +2000,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: @@ -1995,7 +2042,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; } @@ -2017,7 +2064,24 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, 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_TIME32_X86: + unit = sizeof(struct compat_snd_timer_tread64_x86_32); + break; + case TREAD_FORMAT_64BIT: + case TREAD_FORMAT_TIME64: + unit = sizeof(struct snd_timer_tread64); + break; + case TREAD_FORMAT_TIME32: + unit = sizeof(struct snd_timer_tread); + 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) { @@ -2057,9 +2121,48 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, spin_unlock_irq(&tu->qlock); if (tu->tread) { - if (copy_to_user(buffer, &tu->tqueue[qhead], - sizeof(struct snd_timer_tread))) - err = -EFAULT; + struct snd_timer_tread64 *tread = &tu->tqueue[qhead]; + struct snd_timer_tread tread32; + struct compat_snd_timer_tread64_x86_32 compat_tread64; + + switch (tu->tread) { + case TREAD_FORMAT_TIME32_X86: + memset(&compat_tread64, 0, sizeof(compat_tread64)); + compat_tread64 = (struct compat_snd_timer_tread64_x86_32) { + .event = tread->event, + .tstamp_sec = tread->tstamp_sec, + .tstamp_nsec = tread->tstamp_nsec, + .val = tread->val, + }; + + if (copy_to_user(buffer, &compat_tread64, + sizeof(compat_tread64))) + err = -EFAULT; + break; + case TREAD_FORMAT_64BIT: + case TREAD_FORMAT_TIME64: + if (copy_to_user(buffer, tread, + sizeof(struct snd_timer_tread64))) + err = -EFAULT; + break; + case TREAD_FORMAT_TIME32: + memset(&tread32, 0, sizeof(tread32)); + tread32 = (struct snd_timer_tread) { + .event = tread->event, + .tstamp = { + .tv_sec = tread->tstamp_sec, + .tv_nsec = tread->tstamp_nsec, + }, + .val = tread->val, + }; + + if (copy_to_user(buffer, &tread32, sizeof(tread32))) + err = -EFAULT; + break; + default: + err = -ENOTSUPP; + break; + } } else { if (copy_to_user(buffer, &tu->queue[qhead], sizeof(struct snd_timer_read))) diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index 3e09548..866e090 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -110,7 +110,15 @@ static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, uns 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); + { + struct snd_timer_user *tu = file->private_data; + long ret; + + mutex_lock(&tu->ioctl_lock); + ret = __snd_timer_user_ioctl(file, cmd, arg, false); + mutex_unlock(&tu->ioctl_lock); + return ret; + } case SNDRV_TIMER_IOCTL_GPARAMS32: return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: