Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbdIVLnS (ORCPT ); Fri, 22 Sep 2017 07:43:18 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:35801 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752080AbdIVLnR (ORCPT ); Fri, 22 Sep 2017 07:43:17 -0400 X-Google-Smtp-Source: AOwi7QCXDbp/gLjy6lhQ97ba5hAn4G+yrvEu7MPirkujbEDu4DjA5fPpW1nQWvlkkC0XF9n0uP0iuKvO6jZ2slXRuho= MIME-Version: 1.0 In-Reply-To: References: <78aa803db47d99c2bee1a4dc8d426621324785b8.1505973912.git.baolin.wang@linaro.org> From: Arnd Bergmann Date: Fri, 22 Sep 2017 13:43:16 +0200 X-Google-Sender-Auth: _PY2hYpBUvzsUF36NxQZwiSfmNg Message-ID: Subject: Re: [RFC PATCH 2/7] sound: core: Avoid using timespec for struct snd_pcm_status To: Takashi Iwai Cc: Baolin Wang , Jaroslav Kysela , alsa-devel@alsa-project.org, Arvind Yadav , Bhumika Goyal , Deepa Dinamani , Liam Girdwood , dharageswari.r@intel.com, gudishax.kranthikumar@intel.com, guneshwor.o.singh@intel.com, hardik.t.shah@intel.com, jeeja.kp@intel.com, Naveen M , Vinod Koul , Mark Brown , Ingo Molnar , Dan Carpenter , Takashi Sakamoto , Fabian Frederick , SF Markus Elfring , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2973 Lines: 64 On Fri, Sep 22, 2017 at 12:49 PM, Takashi Iwai wrote: > On Fri, 22 Sep 2017 12:14:55 +0200, > Arnd Bergmann wrote: >> The kernel uses timespec64 internally, which is defined as >> "{ s64 tv_sec; long tv_nsec };", so this has the padding >> in a different place on big-endian architectures, and has a >> different alignment and size on i386. We plan to introduce >> a 'struct __kernel_timespec' that is compatible with the >> __64_BIT_TIME_T version of the user timespec, but that >> doesn't exist yet. >> >> If you prefer, we can probably introduce it now with Baolin's >> series, I think Deepa was planning to post a patch to add >> it soon anyway. > > Yes, this sounds like a saner solution than defining the own timespec > at each place individually. Then we can have better conversion > macros, too, I suppose. Thinking about it again, we unfortunately can't use __kernel_timespec until after all 32-bit architectures have been converted to use the new syscalls that we still need to introduce: In the meantime the plan is that '__kernel_timespec' is an alias for the usual 'timespec' in user space and may still be 32-bit wide. I definitely agree that open-coding 'struct { s64 tv_sec; s64 tv_nsec}' in a dozen locations is not overly helpful. I suggested a different alternative in my reply to patch 3/7. Can you have a look at that? The idea would be that we just flatten all the structures in the ioctl implementation and make the structure definition very explicit using u32/s32/u64/s64 members with no implied padding or architecture-specific types. > And, if we have kernel_timespec (or kernel_timespec64 or such), can > this deprecate the existing timespec64 usages, too? I see that > timespec64 is internal only, so consolidation would be beneficial for > code simplification. Our current longterm plan is to only use __kernel_timespec on the ABI side, where we have to watch out for the tricky conversion of tv_nsec: Any timespec copied from a 32-bit process into the kernel must ignore the upper half of the nanoseconds, while copying the same structure from a 64-bit process must return an error if the 64-bit nanoseconds are larger than 999999999. When copying a timespec into user space, we have to be careful to zero the upper half of tv_nsec to avoid leaking uninitialized kernel data. Inside of the kernel, we can ignore those constraints, so I'd keep using the timespec64. We certainly don't want to use the 64-bit nanoseconds field for internal uses on 32-bit kernels, as that would introduce expensive 64-bit arithmetic in a lot of places that don't need it. My hope is also that we can eventually deprecate any use of the plain 'timespec' in the kernel: all internal users should migrate to timespec64 (one at a time, so we can properly review the changes), and the uapi uses should either have the 64-bit version of __kernel_timespec, or use compat_timespec once that becomes usable on 32-bit architectures. Arnd