From patchwork Tue Apr 24 12:06:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134067 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2150698lji; Tue, 24 Apr 2018 05:07:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/715LlxFNL6WjpoxxybYiL7Cm+pB9bdqLMiB7zyjO6asVAk7feBrIUb8GSFOy7kWD9NSMN X-Received: by 10.99.124.72 with SMTP id l8mr15596109pgn.420.1524571658221; Tue, 24 Apr 2018 05:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571658; cv=none; d=google.com; s=arc-20160816; b=SAIm1PBlD4kDwX+x/gIPpwH/PdxxevOaIx4YdhJuSFkM1oakuZHGOMnw/i1tj+OZ6U TK333iQk832NAUxo+0XDryMOlctKeBp2oo/lxlfk0CuclYEWe81+sXPfG4GydCCMpKRu 11r5zkuFgI1mNdiRc5VLpjUII/SiIiysozRULCgm+M2wbK0IxbRtfWDrxTFm+yrGXK9K Xgioc2DyxRrQ63Z4WOdkW92lMNC3kFK6+RVMCBrTO1ZzZrEw/tIScyXnn6VwHvWue/7p tFY22i5pdpz/V4WSLzFeHDVLz0GU4skvhA52pF1IpqG23BzgT0qjbYdlvCPqotJdlxu6 i1Lw== 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=vUyTPQbeeV5LPYBWuuFi98dtmXZHDhJSABAC2yF64hU=; b=bRKUJVJ6ebCLOfufeN99aINhMW8bRGej5DU1m33OBbu0cGYZYubCd7hF794NZ6apAA wtEMJTUmWEE2PT2H789IaXhugwzmlDsAqY8os6sf+tPrTIj2dDpVH+/hn7dKW82+MpYf c7lPRwN7IWzAeHYXz0eQB/9DN5PCJABfYBFRTM086NacVeftDEGNueD78SW+MMam4dqg h/SNURi4y6pezNR1dVJWDe6p5szVWQLbdG5fqepCZ7/MDESWfd0262gGLa+9KYZUItIJ ob0cWodDSIdXxC6O2fGZs16fxEtjPfpFSoX0rYJHumgezGZ9+h9accjSHTUU8GpumNh3 XGvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JmhJu2Sy; 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 p5si10902344pgu.158.2018.04.24.05.07.36; Tue, 24 Apr 2018 05:07:38 -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=JmhJu2Sy; 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 S932580AbeDXMHe (ORCPT + 29 others); Tue, 24 Apr 2018 08:07:34 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35380 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756988AbeDXMH3 (ORCPT ); Tue, 24 Apr 2018 08:07:29 -0400 Received: by mail-pg0-f65.google.com with SMTP id j11so10722477pgf.2 for ; Tue, 24 Apr 2018 05:07:29 -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=vUyTPQbeeV5LPYBWuuFi98dtmXZHDhJSABAC2yF64hU=; b=JmhJu2SyxWmLE9XiGbtmaDXnVLGDjaC2ZSUBRfYNhG3JntPGeuo0Rpca4h16HGW50L 8fhxl9DttyYKBPd/tdc4h6n/7KQg3jnEnVFJmOrbp4Q1i97ynYsMZNUqKx0CIZZOr8oD W+z+CkhQhdtWOdrarioirhNAOBWkcm2kh+iMc= 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=vUyTPQbeeV5LPYBWuuFi98dtmXZHDhJSABAC2yF64hU=; b=uSXgIyvcG828fpc8bkQpZgJHqBDxZdWqvrbfcTsvOYYiv6PxAWd5FnkZ9I8Lv/RFCF XGaFa7Qtsu5PvREWn4CwymEz+PwbX0mY/on2C3TdZhW0NshZH5LJizCFRi4S5kX2leRb JzubEhBlQmNdN/UvMlhzn/LQi7zZl0xM9cYb5aWZpXWWVS/TtaybmuH7+E2Ouak1BCyo 16/c0Vp95UcsAP5A1TkrsFAgCqtJSjspmXwISENOrcFA/A+MLAWNJ8BELwbYwTQ7tIjr 884FAFXU84oWiTWc/qDB9DLhyz/ZNxGHuLnMROdgSngZChXUYgN6eM3xXq9IDaDB31qh sbNg== X-Gm-Message-State: ALQs6tBz6XFoUvZOhh2xaAtL+vq/Ce20QRUZMMwKu3VZcHfcZBXRwM40 Q/mOU7mg85sER0x1O9P2MfrjDQ== X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr24705422plg.23.1524571648819; Tue, 24 Apr 2018 05:07:28 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.23 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:28 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: baolin.wang@linaro.org, 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 Subject: [PATCH 3/8] ALSA: Avoid using timespec for struct snd_ctl_elem_value Date: Tue, 24 Apr 2018 20:06:10 +0800 Message-Id: <33f88d93c2330a17c50c51f1d0e7742f4d27c12a.1524570852.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. >From Takashi's comments, "In the library, applications are not expected to access to this structure directly. The applications get opaque pointer to the structure and must use any control APIs to operate it. Actually the library produce no API to handle 'struct snd_ctl_elem_value.tstamp'. This means that we can drop this member from alsa-lib without decline of functionality." Thus we can simply remove the tstamp member to avoid using the type which is not year 2038 safe on 32bits system. Signed-off-by: Baolin Wang --- include/uapi/sound/asound.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 1.7.9.5 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index ed0a120..1231f0a 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -954,8 +954,7 @@ struct snd_ctl_elem_value { } bytes; struct snd_aes_iec958 iec958; } value; /* RO */ - struct timespec tstamp; - unsigned char reserved[128-sizeof(struct timespec)]; + unsigned char reserved[128]; }; struct snd_ctl_tlv { From patchwork Tue Apr 24 12:06:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134068 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2150857lji; Tue, 24 Apr 2018 05:07:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpHs6tfiqlguywoLf7AH5Lv3JmiRTJLVKd/aEJ0ZA3tBu+C0u+jtYx1YN2q5RZrHKT6iaXU X-Received: by 10.99.47.4 with SMTP id v4mr605583pgv.42.1524571666096; Tue, 24 Apr 2018 05:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571666; cv=none; d=google.com; s=arc-20160816; b=izC/qOwVyt6Xi1Bn3uL29I+dM6ewxQWlJKLFxmj1658bgkFnUimmLEt3RMAyxJQIMd gMdPv2/4JhHy2rcIYhNuFPRHMQpWKrEV5TT0iZ43+wLvR5vG4OD85xy9+cctbQ0w8AJm 98DKlQ1k23CvABPB3TqW3Cre3hAn4oeeJCRuIX8ZyzJXqoLjwmFXjDjo8s2NTOQSi1H1 TgHbxBD781zcy74Ln+6h6qr+OBX1eerDC98t4Ge5mJ6Vergd61BmX7kXnqRWjUjNN6Wr xW0DDOK00nMyLSa/2KTZEe9R11r+hJOgnQBSh7TB1cnI3Xews8i8KT6F+DDWyg0RSE+0 zM7g== 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=uY+YCIF94eUFaOF2arT2mFX7wNjzpA4tGrKsMOMRaYE=; b=cBmF/PX3gwXBCEBffYmT/JgCJh4VTBQDiDN5/VD4YCctT42d0s4Rb4l0VLR0fNyvl3 3cRwNBxeZhTniF42cB03ln8FgYkOTLFJQWlEWowpMRkmHDDXZYXDV4yg0aQnyhcD8FYk i3mBaNV4Tj+I5Woqf6H88Be+nI+C2w677JJOtFKy/iOizvKZJK7pdtj6Q9G251in8DWa 65ZMbAFeJLNNYB9HTessOLeIk5Rgssst6lTtGSjvzCseNvZ/5mNQ3dCR92eh7bJApNiE J7v8j/Q/7KGL981MDcbzivXFNYWZHA0fZhLcms1vE1WEBQK6Cw4dYRhOzU9ER/F2CHNd jQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MsgS+Tts; 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 p5si10902344pgu.158.2018.04.24.05.07.45; Tue, 24 Apr 2018 05:07: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=MsgS+Tts; 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 S932810AbeDXMHn (ORCPT + 29 others); Tue, 24 Apr 2018 08:07:43 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33059 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932561AbeDXMHe (ORCPT ); Tue, 24 Apr 2018 08:07:34 -0400 Received: by mail-pf0-f194.google.com with SMTP id f15so12089836pfn.0 for ; Tue, 24 Apr 2018 05:07: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=uY+YCIF94eUFaOF2arT2mFX7wNjzpA4tGrKsMOMRaYE=; b=MsgS+TtsQJwL+kCxrkNK2qiDirE18ayUY6ML60XLWXOSlFV0UNN1VG/6Y9Mgn4qj1k eFFMx5VSTyI6pejb9E+0vcld1Cs0XASzR6Fkqw+RcYwDDT36nZCPv9NPysKpde1ADQ2t MtoZHuXmAMyBrgiq0SItJZfas18m+qmMnhrjo= 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=uY+YCIF94eUFaOF2arT2mFX7wNjzpA4tGrKsMOMRaYE=; b=XLFSUOS2EQ/qKgCQmG/9kKug7RPKiYOxZXDbeSL3vyb56e+/Wq7CVqXissTXVthLvZ PEsKG6f01L6oy8CG/psYT4sVqNCwrL+xxBFfcbDGCzzzwR3YtcpCDxO9KH448R2R+y5R qM8s9/WvWHa2DIXWyrQzYAaI0PwQkfn/m8YDYiub9Va/oi8QwsE15MCbkeDuAYI2HQ0s 92yw1V5qpQ6k5mF/OxspB5MWKASPqXMBVd+xpO6Ey2a9NSScSCpzXsrkMNqDaMc9IRQn 5+c+k2HgOCY7mFJfYTvZErQoN0I+gYoK1nNXIo0c9LOrIk079FanMLX0YP9HYg70fd4D BH0g== X-Gm-Message-State: ALQs6tANaoothZ1o9JunAWKYbvA8X4WnUoUFIweAkkSUQ4J861ik/Ap8 0i4lCkDzclOIc5Jyvwcqgzlvqw== X-Received: by 10.98.109.66 with SMTP id i63mr23710955pfc.233.1524571653995; Tue, 24 Apr 2018 05:07:33 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.29 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:33 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: baolin.wang@linaro.org, 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 Subject: [PATCH 4/8] ALSA: Avoid using timespec for struct snd_pcm_status Date: Tue, 24 Apr 2018 20:06:11 +0800 Message-Id: <7809a25514e8f7f72a276d19414346b2e4100945.1524570852.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_status will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Userspace will use SNDRV_PCM_IOCTL_STATUS and SNDRV_PCM_IOCTL_STATUS_EXT as commands to issue ioctl() to fill the 'snd_pcm_status' structure in userspace. The command number is always defined through _IOR/_IOW/IORW, so when userspace changes the definition of 'struct timespec' to use 64-bit types, the command number also changes. Thus in the kernel, we now need to define two versions of each such ioctl and corresponding ioctl commands to handle 32bit time_t and 64bit time_t in native mode: struct snd_pcm_status32 { ...... s32 trigger_tstamp_sec; s32 trigger_tstamp_nsec; ...... s32 audio_tstamp_sec; s32 audio_tstamp_nsec; ...... }; struct snd_pcm_status64 { ...... s32 trigger_tstamp_sec; s32 trigger_tstamp_nsec; ...... s32 audio_tstamp_sec; s32 audio_tstamp_nsec; ...... }; Moreover in compat file, we renamed or introduced new structures to handle 32bit/64bit time_t in compatible mode. The 'struct snd_pcm_status32' and snd_pcm_status_user32() are used to handle 32bit time_t in compat mode. 'struct compat_snd_pcm_status64' and snd_pcm_status_user_compat64() are used to handle 64bit time_t. Finally we can replace SNDRV_PCM_IOCTL_STATUS and SNDRV_PCM_IOCTL_STATUS_EXT with new commands and introduce new functions to fill new 'struct snd_pcm_status64' instead of using unsafe 'struct snd_pcm_status'. Then in future, the new commands can be matched when userspace changes 'timespec' to 64bit type to make a size change of 'struct snd_pcm_status'. When glibc changes time_t to 64-bit, any recompiled program will issue ioctl commands that the kernel does not understand without this patch. Signed-off-by: Baolin Wang --- include/sound/pcm.h | 56 +++++++++++++++- include/uapi/sound/asound.h | 1 + sound/core/pcm.c | 12 ++-- sound/core/pcm_compat.c | 154 +++++++++++++++---------------------------- sound/core/pcm_native.c | 96 ++++++++++++++++++++++----- 5 files changed, 193 insertions(+), 126 deletions(-) -- 1.7.9.5 diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 973d674..398e81d 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 */ @@ -573,8 +574,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); @@ -1448,4 +1449,55 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format) #define pcm_dbg(pcm, fmt, args...) \ dev_dbg((pcm)->card->dev, fmt, ##args) +struct snd_pcm_status64 { + snd_pcm_state_t state; /* stream state */ + u8 rsvd[sizeof(time_t) - sizeof(snd_pcm_state_t)]; + s64 trigger_tstamp_sec; /* time when stream was started/stopped/paused */ + s64 trigger_tstamp_nsec; + s64 tstamp_sec; /* reference timestamp */ + s64 tstamp_nsec; + snd_pcm_uframes_t appl_ptr; /* appl ptr */ + snd_pcm_uframes_t hw_ptr; /* hw ptr */ + snd_pcm_sframes_t delay; /* current delay in frames */ + snd_pcm_uframes_t avail; /* number of frames available */ + snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */ + snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ + snd_pcm_state_t suspended_state; /* suspended stream state */ + __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ + s64 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */ + s64 audio_tstamp_nsec; + s64 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */ + s64 driver_tstamp_nsec; + __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ + unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */ +}; + +#define SNDRV_PCM_IOCTL_STATUS64 _IOR('A', 0x20, struct snd_pcm_status64) +#define SNDRV_PCM_IOCTL_STATUS_EXT64 _IOWR('A', 0x24, struct snd_pcm_status64) + +struct snd_pcm_status32 { + s32 state; /* stream state */ + s32 trigger_tstamp_sec; /* time when stream was started/stopped/paused */ + s32 trigger_tstamp_nsec; + s32 tstamp_sec; /* reference timestamp */ + s32 tstamp_nsec; + u32 appl_ptr; /* appl ptr */ + u32 hw_ptr; /* hw ptr */ + s32 delay; /* current delay in frames */ + u32 avail; /* number of frames available */ + u32 avail_max; /* max frames available on hw since last status */ + u32 overrange; /* count of ADC (capture) overrange detections from last status */ + s32 suspended_state; /* suspended stream state */ + u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ + s32 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */ + s32 audio_tstamp_nsec; + s32 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */ + s32 driver_tstamp_nsec; + u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ + unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */ +}; + +#define SNDRV_PCM_IOCTL_STATUS32 _IOR('A', 0x20, struct snd_pcm_status32) +#define SNDRV_PCM_IOCTL_STATUS_EXT32 _IOWR('A', 0x24, struct snd_pcm_status32) + #endif /* __SOUND_PCM_H */ diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 1231f0a..c9afde4 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -457,6 +457,7 @@ enum { struct snd_pcm_status { snd_pcm_state_t state; /* stream state */ + unsigned char pad1[sizeof(time_t) - sizeof(snd_pcm_state_t)]; /* align to timespec */ struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ struct timespec tstamp; /* reference timestamp */ snd_pcm_uframes_t appl_ptr; /* appl ptr */ diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 66ac89a..74d2580 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -456,7 +456,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); @@ -466,17 +466,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..a4ef13b 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -187,73 +187,13 @@ static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, snd_pcm_channel_info_user(s, p) #endif /* CONFIG_X86_X32 */ -struct snd_pcm_status32 { +struct compat_snd_pcm_status64 { s32 state; - struct compat_timespec trigger_tstamp; - struct compat_timespec tstamp; - u32 appl_ptr; - u32 hw_ptr; - s32 delay; - u32 avail; - u32 avail_max; - u32 overrange; - s32 suspended_state; - u32 audio_tstamp_data; - struct compat_timespec audio_tstamp; - struct compat_timespec driver_tstamp; - u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct compat_timespec)]; -} __attribute__((packed)); - - -static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, - struct snd_pcm_status32 __user *src, - bool ext) -{ - struct snd_pcm_status status; - int err; - - memset(&status, 0, sizeof(status)); - /* - * with extension, parameters are read/write, - * get audio_tstamp_data from user, - * ignore rest of status structure - */ - if (ext && get_user(status.audio_tstamp_data, - (u32 __user *)(&src->audio_tstamp_data))) - return -EFAULT; - err = snd_pcm_status(substream, &status); - if (err < 0) - return err; - - if (clear_user(src, sizeof(*src))) - return -EFAULT; - if (put_user(status.state, &src->state) || - compat_put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - compat_put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.appl_ptr, &src->appl_ptr) || - put_user(status.hw_ptr, &src->hw_ptr) || - put_user(status.delay, &src->delay) || - put_user(status.avail, &src->avail) || - put_user(status.avail_max, &src->avail_max) || - put_user(status.overrange, &src->overrange) || - put_user(status.suspended_state, &src->suspended_state) || - put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) || - put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) - return -EFAULT; - - return err; -} - -#ifdef CONFIG_X86_X32 -/* X32 ABI has 64bit timespec and 64bit alignment */ -struct snd_pcm_status_x32 { - s32 state; - u32 rsvd; /* alignment */ - struct timespec trigger_tstamp; - struct timespec tstamp; + u8 rsvd[sizeof(time_t) - sizeof(s32)]; /* alignment */ + s64 trigger_tstamp_sec; + s64 trigger_tstamp_nsec; + s64 tstamp_sec; + s64 tstamp_nsec; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -262,22 +202,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 +230,39 @@ static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&src->audio_tstamp_data))) return -EFAULT; - err = snd_pcm_status(substream, &status); + err = snd_pcm_status64(substream, &status); if (err < 0) return err; if (clear_user(src, sizeof(*src))) return -EFAULT; - if (put_user(status.state, &src->state) || - put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - put_timespec(&status.tstamp, &src->tstamp) || - put_user(status.appl_ptr, &src->appl_ptr) || - put_user(status.hw_ptr, &src->hw_ptr) || - put_user(status.delay, &src->delay) || - put_user(status.avail, &src->avail) || - put_user(status.avail_max, &src->avail_max) || - put_user(status.overrange, &src->overrange) || - put_user(status.suspended_state, &src->suspended_state) || - put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - put_timespec(&status.driver_tstamp, &src->driver_tstamp) || - put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) + + compat_status64 = (struct compat_snd_pcm_status64) { + .state = status.state, + .trigger_tstamp_sec = status.trigger_tstamp_sec, + .trigger_tstamp_nsec = status.trigger_tstamp_nsec, + .tstamp_sec = status.tstamp_sec, + .tstamp_nsec = status.tstamp_nsec, + .appl_ptr = status.appl_ptr, + .hw_ptr = status.hw_ptr, + .delay = status.delay, + .avail = status.avail, + .avail_max = status.avail_max, + .overrange = status.overrange, + .suspended_state = status.suspended_state, + .audio_tstamp_data = status.audio_tstamp_data, + .audio_tstamp_sec = status.audio_tstamp_sec, + .audio_tstamp_nsec = status.audio_tstamp_nsec, + .driver_tstamp_sec = status.audio_tstamp_sec, + .driver_tstamp_nsec = status.audio_tstamp_nsec, + .audio_tstamp_accuracy = status.audio_tstamp_accuracy, + }; + + if (copy_to_user(src, &compat_status64, sizeof(compat_status64))) return -EFAULT; return err; } -#endif /* CONFIG_X86_X32 */ /* both for HW_PARAMS and HW_REFINE */ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream, @@ -633,8 +585,8 @@ enum { SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32), - SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32), - SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32), + SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32), SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32), SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32), SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32), @@ -644,10 +596,10 @@ enum { SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32), SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32), SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), + SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64), + SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64), #ifdef CONFIG_X86_X32 SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info), - SNDRV_PCM_IOCTL_STATUS_X32 = _IOR('A', 0x20, struct snd_pcm_status_x32), - SNDRV_PCM_IOCTL_STATUS_EXT_X32 = _IOWR('A', 0x24, struct snd_pcm_status_x32), SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32), #endif /* CONFIG_X86_X32 */ }; @@ -697,10 +649,10 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_ioctl_hw_params_compat(substream, 0, argp); case SNDRV_PCM_IOCTL_SW_PARAMS32: return snd_pcm_ioctl_sw_params_compat(substream, argp); - case SNDRV_PCM_IOCTL_STATUS32: - return snd_pcm_status_user_compat(substream, argp, false); - case SNDRV_PCM_IOCTL_STATUS_EXT32: - return snd_pcm_status_user_compat(substream, argp, true); + case SNDRV_PCM_IOCTL_STATUS_COMPAT32: + return snd_pcm_status_user32(substream, argp, false); + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: + return snd_pcm_status_user32(substream, argp, true); case SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_ioctl_sync_ptr_compat(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: @@ -719,11 +671,11 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_ioctl_rewind_compat(substream, argp); case SNDRV_PCM_IOCTL_FORWARD32: return snd_pcm_ioctl_forward_compat(substream, argp); + case SNDRV_PCM_IOCTL_STATUS_COMPAT64: + return snd_pcm_status_user_compat64(substream, argp, false); + case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64: + return snd_pcm_status_user_compat64(substream, argp, true); #ifdef CONFIG_X86_X32 - case SNDRV_PCM_IOCTL_STATUS_X32: - return snd_pcm_status_user_x32(substream, argp, false); - case SNDRV_PCM_IOCTL_STATUS_EXT_X32: - return snd_pcm_status_user_x32(substream, argp, true); case SNDRV_PCM_IOCTL_SYNC_PTR_X32: return snd_pcm_ioctl_sync_ptr_x32(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32: diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index c57dd4b..0c2ec6d 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -857,8 +857,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; @@ -884,14 +884,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, @@ -906,7 +914,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: @@ -936,11 +945,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)); @@ -952,7 +961,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))) @@ -960,6 +969,55 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream, return 0; } +static int snd_pcm_status_user32(struct snd_pcm_substream *substream, + struct snd_pcm_status32 __user * _status, + bool ext) +{ + struct snd_pcm_status64 status64; + struct snd_pcm_status32 status32; + int res; + + memset(&status64, 0, sizeof(status64)); + memset(&status32, 0, sizeof(status32)); + /* + * with extension, parameters are read/write, + * get audio_tstamp_data from user, + * ignore rest of status structure + */ + if (ext && get_user(status64.audio_tstamp_data, + (u32 __user *)(&_status->audio_tstamp_data))) + return -EFAULT; + res = snd_pcm_status64(substream, &status64); + if (res < 0) + return res; + + status32 = (struct snd_pcm_status32) { + .state = status64.state, + .trigger_tstamp_sec = status64.trigger_tstamp_sec, + .trigger_tstamp_nsec = status64.trigger_tstamp_nsec, + .tstamp_sec = status64.tstamp_sec, + .tstamp_nsec = status64.tstamp_nsec, + .appl_ptr = status64.appl_ptr, + .hw_ptr = status64.hw_ptr, + .delay = status64.delay, + .avail = status64.avail, + .avail_max = status64.avail_max, + .overrange = status64.overrange, + .suspended_state = status64.suspended_state, + .audio_tstamp_data = status64.audio_tstamp_data, + .audio_tstamp_sec = status64.audio_tstamp_sec, + .audio_tstamp_nsec = status64.audio_tstamp_nsec, + .driver_tstamp_sec = status64.audio_tstamp_sec, + .driver_tstamp_nsec = status64.audio_tstamp_nsec, + .audio_tstamp_accuracy = status64.audio_tstamp_accuracy, + }; + + if (copy_to_user(_status, &status32, sizeof(status32))) + return -EFAULT; + + return 0; +} + static int snd_pcm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info * info) { @@ -2896,10 +2954,14 @@ static int snd_pcm_common_ioctl(struct file *file, return snd_pcm_hw_free(substream); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params_user(substream, arg); - case SNDRV_PCM_IOCTL_STATUS: - return snd_pcm_status_user(substream, arg, false); - case SNDRV_PCM_IOCTL_STATUS_EXT: - return snd_pcm_status_user(substream, arg, true); + case SNDRV_PCM_IOCTL_STATUS32: + return snd_pcm_status_user32(substream, arg, false); + case SNDRV_PCM_IOCTL_STATUS_EXT32: + return snd_pcm_status_user32(substream, arg, true); + case SNDRV_PCM_IOCTL_STATUS64: + return snd_pcm_status_user64(substream, arg, false); + case SNDRV_PCM_IOCTL_STATUS_EXT64: + return snd_pcm_status_user64(substream, arg, true); case SNDRV_PCM_IOCTL_CHANNEL_INFO: return snd_pcm_channel_info_user(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: From patchwork Tue Apr 24 12:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134069 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2150993lji; Tue, 24 Apr 2018 05:07:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo5DlCGbX7QvPew9ILtbUl3XMYppOl5+K61Is0zIz7k3vizrtllU17+GfbnYnpM9Q2/uUnx X-Received: by 2002:a17:902:b90c:: with SMTP id bf12-v6mr3325232plb.37.1524571673735; Tue, 24 Apr 2018 05:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571673; cv=none; d=google.com; s=arc-20160816; b=KFIowtan+2exq/0vA1OjXl/TqmLN7X0Mx//7VdU1LlaY2VbhS046pwHWXSs84dTyOF q6ObUNn8iiG2EdgvpgucV52Yh6zI79UVByc2VfvxP/DejkGQKIRZKKSBGhY5soN8nhrh 9DPh1Ikk7tsN0O9rDVok0l97oiTaYL77v1jqn2E6wXJG6mfDHJFBviUydQchFsFHHeyF Wiu2U7Y0pFQGueG6PoFUx+/MpkM6BfkfTSWe2gIi169u/jukYob+uNfFl6pIxwSxZsVX mmI0tStpK/3X227/SdaSazh79Re5PUs8cWohbfGTs+hR8MxAUSVG8Uynx60eej6SxgNa G9Gw== 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=OCmcHsSbvhGshM6zLlIP6iy81qjhmrSbYVIsx/7mHWc=; b=jp3JPbUpUK+FTsH7IDTQdTtPpihkZIphY3gkNQqWsRlmC8M/PMhz2GaNEVvpeFOKWk HZR9ivuQQHGN6SGW/dy5sMw7wgSP6INE1vmDXdco2i9G5KHSMlv/hKrcSu30MOgqybUh OpVU3npKLTNERXJHmXc5Byfl85j5SgSe2ki2OPCM98vYRFwUx/db8IWbNHzeOgIaxsgU 7VgOGIy94BCAJtbSesCI5FOqCFNepQenGFvB/bew4cmqcf9WWHbmRS5U23jNejhwkZdC zzixXMwVC15cgaUx28NOQFPvwuLU3TAe6r3zGShgz7Ontb1gj9kuZiB9OJifHRrh5pnJ Qr6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HwxU8pFg; 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 68si11746716pgd.511.2018.04.24.05.07.53; Tue, 24 Apr 2018 05:07:53 -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=HwxU8pFg; 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 S1757022AbeDXMHu (ORCPT + 29 others); Tue, 24 Apr 2018 08:07:50 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:43570 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756101AbeDXMHo (ORCPT ); Tue, 24 Apr 2018 08:07:44 -0400 Received: by mail-pf0-f194.google.com with SMTP id j11so12081421pff.10 for ; Tue, 24 Apr 2018 05:07:44 -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=OCmcHsSbvhGshM6zLlIP6iy81qjhmrSbYVIsx/7mHWc=; b=HwxU8pFgqbCfJEXG9Pz7eS6Rg7dAM6tJlFjT0SNeNXQnKtSl4Vn2HMhftTbBKp28GQ zTtQGV0xm6eYI8/mpqHofc7LxHt9QtS0Amp4ztB44cNxAf7JUmuVqDYnuR7bxNFwUZjv bD7eLBZQRElClrmZ2XNA/41lZQKxiZI8uTuOI= 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=OCmcHsSbvhGshM6zLlIP6iy81qjhmrSbYVIsx/7mHWc=; b=NHGpDONLEkEAi9BEI2ptBnQ4p1BomYn5jEYu/AY3dBk6IHCSe0SCKVE4fZEWHuKoH3 D5wT2k16fIu7apnXY2pP03Q0oYMJJG8tMrAlAtz3RWEkfYJaXvKmKbRTSX2BUYvgL1ui 4Ic1SpMtS49S7gpSNy13otKS5dUB3j4Lhn3BbJpK7AN5aqIJgHFKb+hVha0fClWTxU/v lare5WH+Rer5gCMEM7Kge9PjrWCi5ym/fzsK4FqdsNiqTavezOV9QxLCmML6ZmWiHp2K 20ZNK6MPZvjcSUSnwagvJeWCLfV3MlAwV/psBNbq8EU93+RekuFIbxrqmAGOQ9z5vIgy KNrA== X-Gm-Message-State: ALQs6tBkt6YgJk9vznPwjlrVqjqStcWC6sFDFxrkkRtyocELD5QHrLFj IypX3j3AXHluiaBbVA48JSU+Ew== X-Received: by 2002:a17:902:d807:: with SMTP id a7-v6mr25503985plz.314.1524571664109; Tue, 24 Apr 2018 05:07:44 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.39 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:43 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: baolin.wang@linaro.org, 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 Subject: [PATCH 6/8] ALSA: Avoid using timespec for struct snd_timer_tread Date: Tue, 24 Apr 2018 20:06:13 +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. That means we will set tu->tread = TREAD_FORMAT_64BIT when user space has a 64bit time_t, then we will copy to user with struct snd_timer_tread64. Otherwise we will use 32bit time_t variables when copying to user. Moreover this patch replaces timespec type with timespec64 type and related y2038 safe APIs. Signed-off-by: Baolin Wang --- include/uapi/sound/asound.h | 13 +++- sound/core/timer.c | 144 ++++++++++++++++++++++++++++++++----------- sound/core/timer_compat.c | 2 +- 3 files changed, 121 insertions(+), 38 deletions(-) -- 1.7.9.5 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index fad66ad..f368e80 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -773,7 +773,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) @@ -786,6 +786,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; @@ -813,8 +822,10 @@ enum { struct snd_timer_tread { int event; + __u8 pad1[sizeof(time_t) - sizeof(int)]; struct timespec tstamp; unsigned int val; + __u8 pad2[sizeof(time_t) - sizeof(unsigned int)]; }; /**************************************************************************** diff --git a/sound/core/timer.c b/sound/core/timer.c index c9d7ddb..729a643 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -58,6 +58,21 @@ MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER); MODULE_ALIAS("devname:snd/timer"); +enum timer_tread_format { + TREAD_FORMAT_NONE = 0, + TREAD_FORMAT_TIME64, + TREAD_FORMAT_TIME32, +}; + +struct snd_timer_tread64 { + int event; + u8 pad1[sizeof(time_t) - sizeof(int)]; + s64 tstamp_sec; + s64 tstamp_nsec; + unsigned int val; + u32 pad2; +}; + struct snd_timer_user { struct snd_timer_instance *timeri; int tread; /* enhanced read with timestamps and events */ @@ -69,7 +84,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; @@ -1306,7 +1321,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++; @@ -1323,7 +1338,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 && @@ -1333,7 +1348,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); @@ -1355,7 +1371,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; @@ -1376,7 +1392,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; @@ -1390,14 +1407,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++; @@ -1412,7 +1431,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); @@ -1841,11 +1860,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 { @@ -1963,6 +1982,36 @@ 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 (cmd == SNDRV_TIMER_IOCTL_TREAD64 || + (IS_ENABLED(CONFIG_64BITS) && !compat)) + tu->tread = TREAD_FORMAT_TIME64; + else + tu->tread = TREAD_FORMAT_TIME32; + + if (tu->tread != old_tread && + realloc_user_queue(tu, tu->queue_size) < 0) { + tu->tread = old_tread; + return -ENOMEM; + } + + return 0; +} + enum { SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20), SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21), @@ -1971,7 +2020,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; @@ -1983,23 +2032,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: @@ -2039,7 +2074,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; } @@ -2055,13 +2090,28 @@ static int snd_timer_user_fasync(int fd, struct file * file, int on) static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, size_t count, loff_t *offset) { + struct snd_timer_tread64 *tread; + struct snd_timer_tread tread32; struct snd_timer_user *tu; long result = 0, unit; int qhead; int err = 0; tu = file->private_data; - unit = tu->tread ? sizeof(struct snd_timer_tread) : sizeof(struct snd_timer_read); + switch (tu->tread) { + case TREAD_FORMAT_TIME64: + unit = sizeof(struct snd_timer_tread64); + break; + case TREAD_FORMAT_TIME32: + unit = sizeof(struct snd_timer_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) { @@ -2100,14 +2150,36 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, tu->qused--; spin_unlock_irq(&tu->qlock); - if (tu->tread) { - if (copy_to_user(buffer, &tu->tqueue[qhead], - sizeof(struct snd_timer_tread))) + tread = &tu->tqueue[qhead]; + + switch (tu->tread) { + case TREAD_FORMAT_TIME64: + if (copy_to_user(buffer, tread, + sizeof(struct snd_timer_tread64))) err = -EFAULT; - } else { + break; + case TREAD_FORMAT_TIME32: + memset(&tread32, 0, sizeof(tread32)); + tread32 = (struct snd_timer_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; + case TREAD_FORMAT_NONE: if (copy_to_user(buffer, &tu->queue[qhead], sizeof(struct snd_timer_read))) err = -EFAULT; + break; + default: + err = -ENOTSUPP; + break; } spin_lock_irq(&tu->qlock); diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index 0495ede..bef7f87 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -111,7 +111,7 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, case SNDRV_TIMER_IOCTL_PAUSE: case SNDRV_TIMER_IOCTL_PAUSE_OLD: case SNDRV_TIMER_IOCTL_NEXT_DEVICE: - return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp); + return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp, true); case SNDRV_TIMER_IOCTL_GPARAMS32: return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: From patchwork Tue Apr 24 12:06:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134070 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2151201lji; Tue, 24 Apr 2018 05:08:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Qh9kmk7HeHXjIx2QxjXaxwLn14Ms8nmNYkXYGbyTy9m+qaNKTPAJXoDIjLI3dRwtURt8M X-Received: by 10.98.46.5 with SMTP id u5mr23519840pfu.247.1524571683121; Tue, 24 Apr 2018 05:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571683; cv=none; d=google.com; s=arc-20160816; b=PQbtc/otv5EwZTDeCj7gGeIF1/M4QyXGnq+g28XvcdO2CLmN+/+cPM8Q7AKkYfzbTF nEXngEDLcBcDUVsFVZ7px6Dzprd/oNqP9M7btfLh70gVhagiKXnI6ibqyAvfc3A/FOKt rXegVjbfw78+QF8MZ5P4Tnr+C451x6mz92jFHPc6rsL2Qnp55/J/tFEn8l6Zzbq5mjqb dTmvms1NtWmeXCbK7Q/CkCRQvuAtqUlCecOFYO1KPxqlVzA3uap+946IWGLarirWFA2y IMTPe/3lJsRTD85BxNC8KtozgxubYlhEUjaSTUvFUABtJhVZ+Mn3I7X1FKVGW36r6i1h ofPQ== 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=aunNegfER/ThwhOW7tasRBcKq6tgy4rgmskT3vXl1aw=; b=FIDbpMvL6x2CKdJZSXIvjI2UBe9y8LOY91tC1Wei2EAW6h4CQi38c3On/E0fbTsMQN gkkqFsvRMW0s3/cXU8IvdcSWeWK9FrvMHp1gqrs646hB6CrVcDXLrLNqc5Er2JhzTlZy sI8m84WxBCG4cF8DTPhHaO3ELViqrPIjUnuIp3hipNpHxSjr6dKRSmSZ1hio/pQAjv/S 77k1pkgabUMEcOPT4hKIg0no2juqqYLZDulkdavrFemT6aIkLMhNAbpICUBwtCYKTxQK sG6QhkjCU1toOzae8HBrgUlZ2NLss3XQ00aJdBtUFK/h5tfCUd3ih69RS0pqPPv3UC43 orag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Eh2X9Njt; 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 68si11746716pgd.511.2018.04.24.05.08.02; Tue, 24 Apr 2018 05:08:03 -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=Eh2X9Njt; 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 S1757143AbeDXMH5 (ORCPT + 29 others); Tue, 24 Apr 2018 08:07:57 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:46752 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756817AbeDXMHt (ORCPT ); Tue, 24 Apr 2018 08:07:49 -0400 Received: by mail-pg0-f66.google.com with SMTP id t12so10716100pgp.13 for ; Tue, 24 Apr 2018 05:07:49 -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=aunNegfER/ThwhOW7tasRBcKq6tgy4rgmskT3vXl1aw=; b=Eh2X9NjtnjLhuJYclEOnA6LkoIKCA6laZYRNA0Iy7kv1vljAYrPpVMI+9sPuFAYMYG S+1G/b0QdJITh6qmc4CMHGtaymea2HBRgR6kaLEgcPtIHSYv1nvy1p6A2734D2m9AxD4 g/Dem3KzePUeCUwO5g9goeY27Co7OVhgXpnto= 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=aunNegfER/ThwhOW7tasRBcKq6tgy4rgmskT3vXl1aw=; b=hz8DjyAjYZpEV1W5yIBodtCMcgSaAKNMvhN0QSa5OhQNpUB7I5q/4x6J1Xn8z5QGht GOcPZ+8J7b/igZSRsfQ2b/pudGfB4yeSLJzUmnMS6abTxJ/ltlV4SScPan5rb3SeSIpJ OiVwsQta16sapfYJUSZVOJ6uPL/kWcll+vL6NrnfGZ2xl1WFMYp0vI7INNgpaAoMcwa5 9XLceMfOBDjFb8sm9lybO1wZUgVGRv8OmNWJ0PSsVqpbVkbaWbAwAdJdj90ry/pOE4kD MWNNfKck68eB6El/fhBJFEqUJIxZ9JOmEfQnjeOAzIY0Yfx5WkfTBIgMDzBE4NlogiKI IdlA== X-Gm-Message-State: ALQs6tD4e1uFk+JsxMKMEOssLk2t7PV0CrzHwV/KCznHlKlFsgITQAAo ixgKzt2z/8qFq45w5x7uI4XMNg== X-Received: by 2002:a17:902:694a:: with SMTP id k10-v6mr23968917plt.161.1524571668995; Tue, 24 Apr 2018 05:07:48 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.44 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:48 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: baolin.wang@linaro.org, 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 Subject: [PATCH 7/8] ALSA: move snd_pcm_ioctl_sync_ptr_compat into pcm_native.c Date: Tue, 24 Apr 2018 20:06:14 +0800 Message-Id: <1d250179d195adac2ba479f62ad56e0240173715.1524570852.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 From: Arnd Bergmann This is a preparation patch, moving the compat handler for snd_pcm_ioctl_sync_ptr_compat from pcm_compat.c to pcm_native.c. No other changes are indented. Signed-off-by: Arnd Bergmann Signed-off-by: Baolin Wang --- sound/core/pcm_compat.c | 98 --------------------------------------------- sound/core/pcm_native.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 98 deletions(-) -- 1.7.9.5 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index a4ef13b..5ed30aa 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -102,19 +102,6 @@ struct snd_pcm_sw_params32 { unsigned char reserved[56]; }; -/* recalcuate the boundary within 32bit */ -static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) -{ - snd_pcm_uframes_t boundary; - - if (! runtime->buffer_size) - return 0; - boundary = runtime->buffer_size; - while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) - boundary *= 2; - return boundary; -} - static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream, struct snd_pcm_sw_params32 __user *src) { @@ -405,91 +392,6 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream, return err; } - -struct snd_pcm_mmap_status32 { - s32 state; - s32 pad1; - u32 hw_ptr; - struct compat_timespec tstamp; - s32 suspended_state; - struct compat_timespec audio_tstamp; -} __attribute__((packed)); - -struct snd_pcm_mmap_control32 { - u32 appl_ptr; - u32 avail_min; -}; - -struct snd_pcm_sync_ptr32 { - u32 flags; - union { - struct snd_pcm_mmap_status32 status; - unsigned char reserved[64]; - } s; - union { - struct snd_pcm_mmap_control32 control; - unsigned char reserved[64]; - } c; -} __attribute__((packed)); - -static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, - struct snd_pcm_sync_ptr32 __user *src) -{ - struct snd_pcm_runtime *runtime = substream->runtime; - volatile struct snd_pcm_mmap_status *status; - volatile struct snd_pcm_mmap_control *control; - u32 sflags; - struct snd_pcm_mmap_control scontrol; - struct snd_pcm_mmap_status sstatus; - snd_pcm_uframes_t boundary; - int err; - - if (snd_BUG_ON(!runtime)) - return -EINVAL; - - if (get_user(sflags, &src->flags) || - get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || - get_user(scontrol.avail_min, &src->c.control.avail_min)) - return -EFAULT; - if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { - err = snd_pcm_hwsync(substream); - if (err < 0) - return err; - } - status = runtime->status; - control = runtime->control; - boundary = recalculate_boundary(runtime); - if (! boundary) - boundary = 0x7fffffff; - snd_pcm_stream_lock_irq(substream); - /* FIXME: we should consider the boundary for the sync from app */ - if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) - control->appl_ptr = scontrol.appl_ptr; - else - scontrol.appl_ptr = control->appl_ptr % boundary; - if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) - control->avail_min = scontrol.avail_min; - else - scontrol.avail_min = control->avail_min; - sstatus.state = status->state; - sstatus.hw_ptr = status->hw_ptr % boundary; - sstatus.tstamp = status->tstamp; - sstatus.suspended_state = status->suspended_state; - sstatus.audio_tstamp = status->audio_tstamp; - snd_pcm_stream_unlock_irq(substream); - if (put_user(sstatus.state, &src->s.status.state) || - put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || - put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - compat_put_timespec(&sstatus.audio_tstamp, - &src->s.status.audio_tstamp) || - put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || - put_user(scontrol.avail_min, &src->c.control.avail_min)) - return -EFAULT; - - return 0; -} - #ifdef CONFIG_X86_X32 /* X32 ABI has 64bit timespec and 64bit alignment */ struct snd_pcm_mmap_status_x32 { diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 0c2ec6d..158e85d 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -19,6 +19,7 @@ * */ +#include #include #include #include @@ -2819,6 +2820,106 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, return 0; } +#ifdef CONFIG_COMPAT +struct snd_pcm_mmap_status32 { + s32 state; + s32 pad1; + u32 hw_ptr; + struct compat_timespec tstamp; + s32 suspended_state; + struct compat_timespec audio_tstamp; +} __attribute__((packed)); + +struct snd_pcm_mmap_control32 { + u32 appl_ptr; + u32 avail_min; +}; + +struct snd_pcm_sync_ptr32 { + u32 flags; + union { + struct snd_pcm_mmap_status32 status; + unsigned char reserved[64]; + } s; + union { + struct snd_pcm_mmap_control32 control; + unsigned char reserved[64]; + } c; +} __attribute__((packed)); + +/* recalcuate the boundary within 32bit */ +static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) +{ + snd_pcm_uframes_t boundary; + + if (! runtime->buffer_size) + return 0; + boundary = runtime->buffer_size; + while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) + boundary *= 2; + return boundary; +} + +static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, + struct snd_pcm_sync_ptr32 __user *src) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + volatile struct snd_pcm_mmap_status *status; + volatile struct snd_pcm_mmap_control *control; + u32 sflags; + struct snd_pcm_mmap_control scontrol; + struct snd_pcm_mmap_status sstatus; + snd_pcm_uframes_t boundary; + int err; + + if (snd_BUG_ON(!runtime)) + return -EINVAL; + + if (get_user(sflags, &src->flags) || + get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || + get_user(scontrol.avail_min, &src->c.control.avail_min)) + return -EFAULT; + if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { + err = snd_pcm_hwsync(substream); + if (err < 0) + return err; + } + status = runtime->status; + control = runtime->control; + boundary = recalculate_boundary(runtime); + if (! boundary) + boundary = 0x7fffffff; + snd_pcm_stream_lock_irq(substream); + /* FIXME: we should consider the boundary for the sync from app */ + if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) + control->appl_ptr = scontrol.appl_ptr; + else + scontrol.appl_ptr = control->appl_ptr % boundary; + if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) + control->avail_min = scontrol.avail_min; + else + scontrol.avail_min = control->avail_min; + sstatus.state = status->state; + sstatus.hw_ptr = status->hw_ptr % boundary; + sstatus.tstamp = status->tstamp; + sstatus.suspended_state = status->suspended_state; + sstatus.audio_tstamp = status->audio_tstamp; + snd_pcm_stream_unlock_irq(substream); + if (put_user(sstatus.state, &src->s.status.state) || + put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || + compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.suspended_state, &src->s.status.suspended_state) || + compat_put_timespec(&sstatus.audio_tstamp, + &src->s.status.audio_tstamp) || + put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || + put_user(scontrol.avail_min, &src->c.control.avail_min)) + return -EFAULT; + + return 0; +} +#define __SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), +#endif + static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { struct snd_pcm_runtime *runtime = substream->runtime; From patchwork Tue Apr 24 12:06:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134072 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2151400lji; Tue, 24 Apr 2018 05:08:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+gnZm1pVE7tMTOyP7Jd57JRxDOfVFl2rRu4Aao+reAnSxAwRUkMHxlAlLkj2jSMrQBGXq0 X-Received: by 2002:a17:902:a70c:: with SMTP id w12-v6mr24322344plq.74.1524571692325; Tue, 24 Apr 2018 05:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571692; cv=none; d=google.com; s=arc-20160816; b=IgEm0+5RpUtaeTXCP4vQlnYE0fvUoX5reafLPnlWY9nyAwgJqgkLHweL6fYQps8jnY +32aFRoer+aZ9dTrAVp3MnGYGn3ZhJvIAXEZEFd6LoJqo+MU3o8ewcwFjPMQ908F2Fh/ wxk70IT/mESM75yvlpzIl8DaycnZHyZzw4IMfjKOKmgyq4Qf/d/TFCWDrHoSgFulYGDj 83XOVd10TW4Yucb/U97r4W02ucROsN6jU40BW8kLwWhJ5lbNvaadn1P8REuaG5c6KQHZ OuRhudTqKLFvYSV/xZNx1+3geBpxnNsxt0ygvPQZS1M0cFapL9M0BslCxAF6nRFiXeyh pZFQ== 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=XRUQlrqR4EwZLqG1kx17NO8oBHyEmo8WYjqdSay4mFw=; b=0ktFv/PjYfJwN5fsGsJ6UMK2a2umzfTxoH6QzxD91KVn4Sr8lNfaPKMT+8K8+9+heD Y2RJgDP6l3f3RTzLkQIDec/OJuQhUlFk6L5oSQkr6kp53KCwLukhyoGKPrNNy4DU4QjK JPozr2xmMjSaSz5+QExV+1OxAtFtC8oVZsQ313DvOgBTGHKN/wISyvwqpm3KX7C+jBtM w3BpwpK3IJBb1cYYHDC4va0HC9smslqHqtU9hL411DxkW9MojWTytTajJqqBETpm9tou ef5QB6ayT7EvzEhcr8qIQiRU0zbSQwcxBq38e51bWIJ55I59NhxhAzwjda7DPJ4EHoCH z8Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WyXTXkV0; 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 68si11746716pgd.511.2018.04.24.05.08.11; Tue, 24 Apr 2018 05:08:12 -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=WyXTXkV0; 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 S1757207AbeDXMII (ORCPT + 29 others); Tue, 24 Apr 2018 08:08:08 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:35125 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757056AbeDXMH4 (ORCPT ); Tue, 24 Apr 2018 08:07:56 -0400 Received: by mail-pg0-f45.google.com with SMTP id j11so10723264pgf.2 for ; Tue, 24 Apr 2018 05:07:55 -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=XRUQlrqR4EwZLqG1kx17NO8oBHyEmo8WYjqdSay4mFw=; b=WyXTXkV0WRK3+1amdtPWpkHADMg9VWYJvYlCbNDZ7BxjKPATK1YF6KtBwb/26peIcr NhP1Kb0+HqYEXKyHL3XasAjvhdaB3e/Ae44JFkEBauFEarZVLclQj/b42UdjciiWsokS zk3zejCPrgaYEDSo6P09ZRmKrhycfa3QCa8zs= 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=XRUQlrqR4EwZLqG1kx17NO8oBHyEmo8WYjqdSay4mFw=; b=uaCFii6odr9z+KXfvQsx19hyj8yF+nZAe23Ogojn6QlhXelzUqaDSGuI1wlKCXr+y9 iHQc6e9EYvO1V0t0/1r/Hzvj/RUX4tKBobFHGvrS4TrwUchqp9pDzsrohrlm+n5qADeG yPFUZxWW9EBvmaCRqxsQPTPUznZ2DK5lSuw3EeM5IL+KqsJXJ9G9sMqAlmgOMh+prOxb 9+Qb/uJb1HAfoChzR3+vCkuEQUx2lGwUp30ZWCQQXq/sJTu6WahZFvS3cHM3m3H4poDN pETJc0UxHckWPCmHpi1eetbrJPM8IHZufdpgxTYaBkMJRLUj7M++22x8doVuhPQS9y2S fOjQ== X-Gm-Message-State: ALQs6tAmf7RqaNdIg0GBJHyQLODMhw4e8IY8QVtEmUeKTK+1gBvCiPfq fU/9mmMKvHItu8oHCpvK3RZTYg== X-Received: by 10.99.172.26 with SMTP id v26mr20578181pge.105.1524571674083; Tue, 24 Apr 2018 05:07:54 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.49 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:53 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: baolin.wang@linaro.org, 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 Subject: [PATCH 8/8] ALSA: add new 32-bit layout for snd_pcm_mmap_status/control Date: Tue, 24 Apr 2018 20:06:15 +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 From: Arnd Bergmann The snd_pcm_mmap_status and snd_pcm_mmap_control interfaces are one of the trickiest areas to get right when moving to 64-bit time_t in user space. The snd_pcm_mmap_status structure layout is incompatible with user space that uses a 64-bit time_t, so we need a new layout for it. Since the SNDRV_PCM_IOCTL_SYNC_PTR ioctl combines it with snd_pcm_mmap_control into snd_pcm_sync_ptr, we need to change those two as well. Both structures are also exported via an mmap() operation on certain architectures, and this suffers from incompatibility between 32-bit and 64-bit user space. As we have to change both structures anyway, this is a good opportunity to fix the mmap() problem as well, so let's standardize on the existing 64-bit layout of the structure where possible. The downside is that we lose mmap() support for existing 32-bit x86 and powerpc applications, adding that would introduce very noticeable runtime overhead and complexity. My assumption here is that not too many people will miss the removed feature, given that: - Almost all x86 and powerpc users these days are on 64-bit kernels, the majority of today's 32-bit users are on architectures that never supported mmap (ARM, MIPS, ...). - It never worked in compat mode (it was intentionally disabled there) - The application already needs to work with a fallback to SNDRV_PCM_IOCTL_SYNC_PTR, which will keep working with both the old and new structure layout. Both the ioctl() and mmap() based interfaces are changed at the same time, as they are based on the same structures. Unlike other interfaces, we change the uapi header to export both the traditional structure and a version that is portable between 32-bit and 64-bit user space code and that corresponds to the existing 64-bit layout. We further check the __USE_TIME_BITS64 macro that will be defined by future C library versions whenever we use the new time_t definition, so any existing user space source code will not see any changes until it gets rebuilt against a new C library. However, the new structures are all visible in addition to the old ones, allowing applications to explicitly request the new structures. In order to detect the difference between the old snd_pcm_mmap_status and the new __snd_pcm_mmap_status64 structure from the ioctl command number, we rely on one quirk in the structure definition: snd_pcm_mmap_status must be aligned to alignof(time_t), which leads the compiler to insert four bytes of padding in struct snd_pcm_sync_ptr after 'flags' and a corresponding change in the size of snd_pcm_sync_ptr itself. On x86-32 (and only there), the compiler doesn't use 64-bit alignment in structure, so I'm adding an explicit pad in the structure that has no effect on the existing 64-bit architectures but ensures that the layout matches for x86. The snd_pcm_uframes_t type compatibility requires another hack: we can't easily make that 64 bit wide, so I leave the type as 'unsigned long', but add padding before and after it, to ensure that the data is properly aligned to the respective 64-bit field in the in-kernel structure. For the SNDRV_PCM_MMAP_OFFSET_STATUS/CONTROL constants that are used as the virtual file offset in the mmap() function, we also have to introduce new constants that depend on hte __USE_TIME_BITS64 macro: The existing macros are renamed to SNDRV_PCM_MMAP_OFFSET_STATUS_OLD and SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD, they continue to work fine on 64-bit architectures, but stop working on native 32-bit user space. The replacement _NEW constants are now used by default for user space built with __USE_TIME_BITS64, those now work on all new kernels for x86, ppc and alpha (32 and 64 bit, native and compat). It might be a good idea for a future alsa-lib to support both the _OLD and _NEW macros and use the corresponding structures directly. Unmodified alsa-lib source code will retain the current behavior, so it will no longer be able to use mmap() for the status/control structures on 32-bit systems, until either the C library gets updated to 64-bit time_t or alsa-lib gets updated to support both mmap() layouts. Signed-off-by: Arnd Bergmann Signed-off-by: Baolin Wang --- include/uapi/sound/asound.h | 96 +++++++++++++++++++++++++++++++++++++++---- sound/core/pcm_compat.c | 9 ++-- sound/core/pcm_lib.c | 13 +++--- sound/core/pcm_native.c | 33 +++++++++------ 4 files changed, 120 insertions(+), 31 deletions(-) -- 1.7.9.5 diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index f368e80..18fbdcb 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -34,6 +34,8 @@ #include #endif +#include + /* * protocol version */ @@ -300,7 +302,9 @@ enum { #define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ #define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ - +#if (__BITS_PER_LONG == 32 && defined(__USE_TIME_BITS64)) || defined __KERNEL__ +#define __SND_STRUCT_TIME64 +#endif typedef int __bitwise snd_pcm_state_t; #define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */ @@ -316,8 +320,17 @@ enum { enum { SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000, - SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000, - SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_OLD = 0x80000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD = 0x81000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_NEW = 0x82000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW = 0x83000000, +#ifdef __SND_STRUCT_TIME64 + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_NEW, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW, +#else + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_OLD, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD, +#endif }; union snd_pcm_sync_id { @@ -474,7 +487,22 @@ struct snd_pcm_status { unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */ }; -struct snd_pcm_mmap_status { +/* + * For mmap operations, we need the 64-bit layout, both for compat mode, + * and for y2038 compatibility. For 64-bit applications, the two definitions + * are identical, so we keep the traditional version. + */ +#ifdef __SND_STRUCT_TIME64 +#define __snd_pcm_mmap_status64 snd_pcm_mmap_status +#define __snd_pcm_mmap_control64 snd_pcm_mmap_control +#define __snd_pcm_sync_ptr64 snd_pcm_sync_ptr +#else +#define __snd_pcm_mmap_status snd_pcm_mmap_status +#define __snd_pcm_mmap_control snd_pcm_mmap_control +#define __snd_pcm_sync_ptr snd_pcm_sync_ptr +#endif + +struct __snd_pcm_mmap_status { snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ int pad1; /* Needed for 64 bit alignment */ snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ @@ -483,7 +511,7 @@ struct snd_pcm_mmap_status { struct timespec audio_tstamp; /* from sample counter or wall clock */ }; -struct snd_pcm_mmap_control { +struct __snd_pcm_mmap_control { snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ }; @@ -492,14 +520,64 @@ struct snd_pcm_mmap_control { #define SNDRV_PCM_SYNC_PTR_APPL (1<<1) /* get appl_ptr from driver (r/w op) */ #define SNDRV_PCM_SYNC_PTR_AVAIL_MIN (1<<2) /* get avail_min from driver */ -struct snd_pcm_sync_ptr { +struct __snd_pcm_sync_ptr { unsigned int flags; union { - struct snd_pcm_mmap_status status; + struct __snd_pcm_mmap_status status; + unsigned char reserved[64]; + } s; + union { + struct __snd_pcm_mmap_control control; + unsigned char reserved[64]; + } c; +}; + +struct __snd_timespec64 { + __s64 tv_sec; + __s64 tv_nsec; +}; + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN) +typedef char __pad_before_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +typedef char __pad_after_uframe[0]; +#endif + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) +typedef char __pad_before_uframe[0]; +typedef char __pad_after_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +#endif + +struct __snd_pcm_mmap_status64 { + __s32 state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + __u32 pad1; /* Needed for 64 bit alignment */ + __pad_before_uframe __pad1; + snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ + __pad_after_uframe __pad2; + struct __snd_timespec64 tstamp; /* Timestamp */ + __s32 suspended_state; /* RO: suspended stream state */ + __u32 pad3; /* Needed for 64 bit alignment */ + struct __snd_timespec64 audio_tstamp; /* sample counter or wall clock */ +}; + +struct __snd_pcm_mmap_control64 { + __pad_before_uframe __pad1; + snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ + __pad_before_uframe __pad2; + + __pad_before_uframe __pad3; + snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ + __pad_after_uframe __pad4; +}; + +struct __snd_pcm_sync_ptr64 { + __u32 flags; + __u32 pad1; + union { + struct __snd_pcm_mmap_status64 status; unsigned char reserved[64]; } s; union { - struct snd_pcm_mmap_control control; + struct __snd_pcm_mmap_control64 control; unsigned char reserved[64]; } c; }; @@ -584,6 +662,8 @@ enum { #define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status) #define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t) #define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22) +#define __SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct __snd_pcm_sync_ptr) +#define __SNDRV_PCM_IOCTL_SYNC_PTR64 _IOWR('A', 0x23, struct __snd_pcm_sync_ptr64) #define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr) #define SNDRV_PCM_IOCTL_STATUS_EXT _IOWR('A', 0x24, struct snd_pcm_status) #define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info) diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index 5ed30aa..51a9447 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -497,7 +497,6 @@ enum { SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32), SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32), SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32), - SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64), SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64), #ifdef CONFIG_X86_X32 @@ -521,8 +520,8 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l /* * When PCM is used on 32bit mode, we need to disable - * mmap of PCM status/control records because of the size - * incompatibility. + * mmap of the old PCM status/control records because + * of the size incompatibility. */ pcm_file->no_compat_mmap = 1; @@ -544,6 +543,8 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l case SNDRV_PCM_IOCTL_XRUN: case SNDRV_PCM_IOCTL_LINK: case SNDRV_PCM_IOCTL_UNLINK: + case __SNDRV_PCM_IOCTL_SYNC_PTR32: + case __SNDRV_PCM_IOCTL_SYNC_PTR64: return snd_pcm_common_ioctl(file, substream, cmd, argp); case SNDRV_PCM_IOCTL_HW_REFINE32: return snd_pcm_ioctl_hw_params_compat(substream, 1, argp); @@ -555,8 +556,6 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l return snd_pcm_status_user32(substream, argp, false); case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: return snd_pcm_status_user32(substream, argp, true); - case SNDRV_PCM_IOCTL_SYNC_PTR32: - return snd_pcm_ioctl_sync_ptr_compat(substream, argp); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: return snd_pcm_ioctl_channel_info_compat(substream, argp); case SNDRV_PCM_IOCTL_WRITEI_FRAMES32: diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 213f0e6..6d19e028 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.tv_sec = tstamp.tv_sec; + runtime->status->tstamp.tv_nsec = tstamp.tv_nsec; } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { @@ -253,10 +254,12 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, *audio_tstamp = ns_to_timespec64(audio_nsecs); } - if (!timespec_equal(&runtime->status->audio_tstamp, audio_tstamp)) { - runtime->status->audio_tstamp = - timespec64_to_timespec(*audio_tstamp); - runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); + if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || + runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { + runtime->status->audio_tstamp.tv_sec = audio_tstamp->tv_sec; + runtime->status->audio_tstamp.tv_nsec = audio_tstamp->tv_nsec; + runtime->status->tstamp.tv_sec = curr_tstamp->tv_sec; + runtime->status->tstamp.tv_nsec = curr_tstamp->tv_nsec; } diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 158e85d..7bb14d5 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2820,7 +2820,6 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, return 0; } -#ifdef CONFIG_COMPAT struct snd_pcm_mmap_status32 { s32 state; s32 pad1; @@ -2907,18 +2906,18 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp.tv_sec) || + put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp.tv_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - compat_put_timespec(&sstatus.audio_tstamp, - &src->s.status.audio_tstamp) || + put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp.tv_sec) || + put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp.tv_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; return 0; } -#define __SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32), -#endif +#define __SNDRV_PCM_IOCTL_SYNC_PTR32 _IOWR('A', 0x23, struct snd_pcm_sync_ptr32) static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { @@ -3092,7 +3091,9 @@ static int snd_pcm_common_ioctl(struct file *file, return -EFAULT; return 0; } - case SNDRV_PCM_IOCTL_SYNC_PTR: + case __SNDRV_PCM_IOCTL_SYNC_PTR32: + return snd_pcm_ioctl_sync_ptr_compat(substream, arg); + case __SNDRV_PCM_IOCTL_SYNC_PTR64: return snd_pcm_sync_ptr(substream, arg); #ifdef CONFIG_SND_SUPPORT_OLD_API case SNDRV_PCM_IOCTL_HW_REFINE_OLD: @@ -3472,8 +3473,6 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file) { - if (pcm_file->no_compat_mmap) - return false; /* See pcm_control_mmap_allowed() below. * Since older alsa-lib requires both status and control mmaps to be * coupled, we have to disable the status mmap for old alsa-lib, too. @@ -3686,11 +3685,19 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) offset = area->vm_pgoff << PAGE_SHIFT; switch (offset) { - case SNDRV_PCM_MMAP_OFFSET_STATUS: + case SNDRV_PCM_MMAP_OFFSET_STATUS_OLD: + if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) + return -ENXIO; + /* fallthrough */ + case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: if (!pcm_status_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_status(substream, file, area); - case SNDRV_PCM_MMAP_OFFSET_CONTROL: + case SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD: + if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) + return -ENXIO; + /* fallthrough */ + case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: if (!pcm_control_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_control(substream, file, area); @@ -3850,9 +3857,9 @@ static unsigned long snd_pcm_get_unmapped_area(struct file *file, unsigned long offset = pgoff << PAGE_SHIFT; switch (offset) { - case SNDRV_PCM_MMAP_OFFSET_STATUS: + case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: return (unsigned long)runtime->status; - case SNDRV_PCM_MMAP_OFFSET_CONTROL: + case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: return (unsigned long)runtime->control; default: return (unsigned long)runtime->dma_area + offset;