From: Takashi Iwai <tiwai@suse.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Baolin Wang <baolin.wang@linaro.org>,
Jaroslav Kysela <perex@perex.cz>,
alsa-devel@alsa-project.org,
Arvind Yadav <arvind.yadav.cs@gmail.com>,
Bhumika Goyal <bhumirks@gmail.com>,
Deepa Dinamani <deepa.kernel@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
dharageswari.r@intel.com, gudishax.kranthikumar@intel.com,
guneshwor.o.singh@intel.com, hardik.t.shah@intel.com,
jeeja.kp@intel.com, Naveen M <naveen.m@intel.com>,
Vinod Koul <vinod.koul@intel.com>,
Mark Brown <broonie@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Dan Carpenter <dan.carpenter@oracle.com>,
Takashi Sakamoto <o-takashi@sakamocchi.jp>,
Fabian Frederick <fabf@skynet.be>,
SF Markus Elfring <elfring@users.sourceforge.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 2/7] sound: core: Avoid using timespec for struct snd_pcm_status
Date: Fri, 22 Sep 2017 14:19:46 +0200 [thread overview]
Message-ID: <s5h4lrvdixp.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAK8P3a0Mw+yPCf_SMmoJuAQ-JhrtGxzw0T4-yEK5fYc+P2=dCg@mail.gmail.com>
On Fri, 22 Sep 2017 13:43:16 +0200,
Arnd Bergmann wrote:
>
> On Fri, Sep 22, 2017 at 12:49 PM, Takashi Iwai <tiwai@suse.de> 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.
OK.
> 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.
Thanks, I took a look at it, and I agree with you about the flatten
struct being easier to handle.
Though, one thing is still considered: snd_pcm_mmap_status struct is
not only passed via ioctl but it's embedded in a mmapped context.
So, differentiation by the struct size can't work with it (as already
you pointed about union, too).
It might sound like a contradiction what I wrote, but another possible
way would be to define 64bit timespec for the sound (both 64bit sec
and nsec), and use it consistently in all places no matter which
architecture is used. It'd need the changes in alsa-lib or
tiny-alsa, of course. But that's one of the reasons of the presence
of alsa-lib layer after all.
Recently we introduced the ioctl for user-space to inform the
supported ABI version (SNDRV_PCM_IOCTL_USER_PVERSION). With this, we
can limit the 64bit timespec support only for the programs that issue
this ioctl with the new protocol version. If not set or older ABI
version is given, it means still old 32bit timespec. This can be used
for distinguish which mmapped struct is referred, too.
> > 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.
Right.
> 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.
OK, that's the reason of timespec64. But this can be eventually
identical with __kernel_timespec? It holds 64bit sec and 32bit nsec,
right? The difference is the presence of padding, but having a pad
makes things arch-agnostic, so its cost looks paying well, I guess.
> 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.
Heh, let's keep our hope :)
thanks,
Takashi
next prev parent reply other threads:[~2017-09-22 12:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 6:18 [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem Baolin Wang
2017-09-21 6:18 ` [RFC PATCH 1/7] sound: Replace timespec with timespec64 Baolin Wang
2017-09-21 10:02 ` Arnd Bergmann
2017-09-21 6:18 ` [RFC PATCH 2/7] sound: core: Avoid using timespec for struct snd_pcm_status Baolin Wang
2017-09-22 9:31 ` Takashi Iwai
2017-09-22 10:14 ` Arnd Bergmann
2017-09-22 10:49 ` Takashi Iwai
2017-09-22 11:43 ` Arnd Bergmann
2017-09-22 12:19 ` Takashi Iwai [this message]
2017-09-21 6:18 ` [RFC PATCH 3/7] sound: core: Avoid using timespec for struct snd_pcm_sync_ptr Baolin Wang
2017-09-21 12:50 ` Arnd Bergmann
2017-09-22 6:47 ` Baolin Wang
2017-09-22 8:48 ` Arnd Bergmann
2017-09-26 22:24 ` Baolin Wang
2017-09-21 6:18 ` [RFC PATCH 4/7] sound: core: Avoid using timespec for struct snd_rawmidi_status Baolin Wang
2017-09-21 12:56 ` Arnd Bergmann
2017-09-22 1:54 ` Baolin Wang
2017-09-21 6:18 ` [RFC PATCH 5/7] sound: core: Avoid using timespec for struct snd_timer_status Baolin Wang
2017-09-21 13:14 ` Arnd Bergmann
2017-09-22 2:03 ` Baolin Wang
2017-09-21 6:18 ` [RFC PATCH 6/7] uapi: sound: Avoid using timespec for struct snd_ctl_elem_value Baolin Wang
2017-09-21 12:58 ` Arnd Bergmann
2017-09-26 21:54 ` Baolin Wang
2017-09-21 6:18 ` [RFC PATCH 7/7] sound: core: Avoid using timespec for struct snd_timer_tread Baolin Wang
2017-09-21 13:09 ` Arnd Bergmann
2017-09-22 3:00 ` Baolin Wang
2017-09-22 7:57 ` Arnd Bergmann
2017-09-22 8:38 ` Baolin Wang
2017-09-22 4:07 ` [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem Takashi Sakamoto
2017-09-22 5:30 ` Baolin Wang
2017-09-22 9:15 ` Mark Brown
2017-09-22 9:17 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s5h4lrvdixp.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=arnd@arndb.de \
--cc=arvind.yadav.cs@gmail.com \
--cc=baolin.wang@linaro.org \
--cc=bhumirks@gmail.com \
--cc=broonie@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=deepa.kernel@gmail.com \
--cc=dharageswari.r@intel.com \
--cc=elfring@users.sourceforge.net \
--cc=fabf@skynet.be \
--cc=gudishax.kranthikumar@intel.com \
--cc=guneshwor.o.singh@intel.com \
--cc=hardik.t.shah@intel.com \
--cc=jeeja.kp@intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=naveen.m@intel.com \
--cc=o-takashi@sakamocchi.jp \
--cc=perex@perex.cz \
--cc=vinod.koul@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox