All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Baolin Wang <baolin.wang@linaro.org>,
	Jaroslav Kysela <perex@perex.cz>,
	Fabian Frederick <fabf@skynet.be>,
	Arvind Yadav <arvind.yadav.cs@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	alsa-devel@alsa-project.org, Vinod Koul <vinod.koul@intel.com>,
	hardik.t.shah@intel.com, guneshwor.o.singh@intel.com,
	Liam Girdwood <lgirdwood@gmail.com>,
	SF Markus Elfring <elfring@users.sourceforge.net>,
	gudishax.kranthikumar@intel.com, Mark Brown <broonie@kernel.org>,
	Bhumika Goyal <bhumirks@gmail.com>, Naveen M <naveen.m@intel.com>,
	jeeja.kp@intel.com, Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	subhransu.s.prusty@intel.com, Ingo Molnar <mingo@kernel.org>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [alsa-devel] [RFC PATCH v2 7/7] sound: core: Avoid using timespec for struct snd_timer_tread
Date: Thu, 09 Nov 2017 17:52:26 +0100	[thread overview]
Message-ID: <s5h1sl7e6np.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAK8P3a39BOUa_2pnHZ6URjv6uKgEtiySEExhE5qEegqfk-CDkg@mail.gmail.com>

On Mon, 06 Nov 2017 17:33:26 +0100,
Arnd Bergmann wrote:
> 
> On Sun, Nov 5, 2017 at 5:59 PM, Takashi Iwai <tiwai@suse.de> wrote:
> > On Sun, 05 Nov 2017 14:16:28 +0100,
> >> On Sun, Nov 5, 2017 at 11:29 AM, Takashi Iwai <tiwai@suse.de> wrote:
> >> > On Thu, 02 Nov 2017 12:06:57 +0100,
> >> > We should introduce SNDRV_TIMER_IOCTL_USER_PVERSION instead, where
> >> > user-space can tell which protocol version it understands.  If the
> >> > protocol version is higher than some definition, we can assume it's
> >> > 64-bit ready.  The *_USER_PVERSION is issued from alsa-lib side.
> >> > In that way, we can extend the ABI more flexibly.  A similar trick was
> >> > already used in PCM ABI.  (Ditto for control and rawmidi API; we
> >> > should have the same mechanism for all relevant APIs).
> >> >
> >> > Moreover, once when the new protocol is used, we can use the standard
> >> > 64bit monotonic nsecs as a timestamp, so that we don't need to care
> >> > about 32/64bit compatibility.
> >>
> >> I think that's fine, we can do that too, but I don't see how we get around
> >> to doing something like Baolin's patch first. Without this, we will get
> >> existing user space code compiling against our kernel headers using a
> >> new glibc release that will inadvertently change the structure layout
> >> on the read file descriptor.
> >
> > But it won't work in anyway in multiple ways, e.g. this timer read
> > stuff and another the structs embedded in the mmappged page.  If you
> > do rebuild things with new glibc, it should tell kernel about the new
> > ABI in anyway more or less explicitly.  And if you need it, it means
> > that some source-code level API change would be possible.
> 
> Right, you mentioned the mmap interface at the kernel summit. This
> is certainly the most tricky part and will probably require source-level
> changes.
> 
> Can you clarify a few things about the mmap() interface?
> Is this specifically about "struct snd_pcm_mmap_status" on the
> pcm device, or are there others?
> 
> From what I can see, it's already fairly limited:
> - on most architectures, it's completely disabled, only x86, ppc and
>   alpha allow it to start with, and user space can work around
>   the mmap not being available by falling back to ioctl if I read
>   the comments correctly
> - alpha is not affected since time_t is always 64-bit
> - x86 and ppc disable the mmap() in compat mode already because
>   of the same issue. If it comes to the worst, we can probably do
>   the same for x86-32 and ppc32, disabling the existing status mmap
>   for them as well, and change SNDRV_PCM_MMAP_OFFSET_STATUS
>   to a new value for 32-bit kernels that exposes the same structure
>   as 64-bit kernels.
> - I think that since we always use an offset that is defined in the
>   header file, we can use the same trick for mmap that we have
>   for the ioctl command number:
> 
> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
> index c227ccba60ae..bcdbdac097d9 100644
> --- a/include/uapi/sound/asound.h
> +++ b/include/uapi/sound/asound.h
> @@ -306,10 +306,19 @@ typedef int __bitwise snd_pcm_state_t;
> 
>  enum {
>         SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000,
> -       SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000,
> +       SNDRV_PCM_MMAP_OFFSET_STATUS_OLD = 0x80000000,
>         SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000,
> +       SNDRV_PCM_MMAP_OFFSET_STATUS64 = 0x82000000,
>  };
> 
> +#if __BITS_PER_LONG == 64
> +#define SNDRV_PCM_MMAP_OFFSET_STATUS SNDRV_PCM_MMAP_OFFSET_STATUS_OLD
> +#else
> +#define SNDRV_PCM_MMAP_OFFSET_STATUS ((sizeof(time_t) >
> sizeof(__kernel_long_t)) ? \
> +                                       SNDRV_PCM_MMAP_OFFSET_STATUS64 : \
> +                                       SNDRV_PCM_MMAP_OFFSET_STATUS_OLD)
> +#endif
> +
>  union snd_pcm_sync_id {
>         unsigned char id[16];
>         unsigned short id16[8];
> 
> Does that make sense?

Yeah, that should work.

But can we make the flip without the dynamic sizeof() comparison but
some ifdef?  The above doesn't allow the usage with switch(), for
example.

IOW, is there any macro indicating the 64bit user time_t?

In theory we can have the shadow mmap for the compat timespec, and
convert it always when the status gets changed.  But I guess disabling
the mmap should work simply as is, judging from the 64bit compat
status.


So, basically speaking, I find all fine with the suggested
conversions.  But, some details look fairly ugly, like the dynamic
const evaluation in the above.  If we can tidy up these devils, the
code will become more readable.


thanks,

Takashi

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: jeeja.kp@intel.com, gudishax.kranthikumar@intel.com,
	alsa-devel@alsa-project.org, Liam Girdwood <lgirdwood@gmail.com>,
	Baolin Wang <baolin.wang@linaro.org>,
	Vinod Koul <vinod.koul@intel.com>,
	hardik.t.shah@intel.com, Ingo Molnar <mingo@kernel.org>,
	guneshwor.o.singh@intel.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Fabian Frederick <fabf@skynet.be>,
	Mark Brown <broonie@kernel.org>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Naveen M <naveen.m@intel.com>,
	Arvind Yadav <arvind.yadav.cs@gmail.com>,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	subhransu.s.prusty@intel.com,
	SF Markus Elfring <elfring@users.sourceforge.net>,
	Bhumika Goyal <bhumirks@gmail.com>
Subject: Re: [RFC PATCH v2 7/7] sound: core: Avoid using timespec for struct snd_timer_tread
Date: Thu, 09 Nov 2017 17:52:26 +0100	[thread overview]
Message-ID: <s5h1sl7e6np.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAK8P3a39BOUa_2pnHZ6URjv6uKgEtiySEExhE5qEegqfk-CDkg@mail.gmail.com>

On Mon, 06 Nov 2017 17:33:26 +0100,
Arnd Bergmann wrote:
> 
> On Sun, Nov 5, 2017 at 5:59 PM, Takashi Iwai <tiwai@suse.de> wrote:
> > On Sun, 05 Nov 2017 14:16:28 +0100,
> >> On Sun, Nov 5, 2017 at 11:29 AM, Takashi Iwai <tiwai@suse.de> wrote:
> >> > On Thu, 02 Nov 2017 12:06:57 +0100,
> >> > We should introduce SNDRV_TIMER_IOCTL_USER_PVERSION instead, where
> >> > user-space can tell which protocol version it understands.  If the
> >> > protocol version is higher than some definition, we can assume it's
> >> > 64-bit ready.  The *_USER_PVERSION is issued from alsa-lib side.
> >> > In that way, we can extend the ABI more flexibly.  A similar trick was
> >> > already used in PCM ABI.  (Ditto for control and rawmidi API; we
> >> > should have the same mechanism for all relevant APIs).
> >> >
> >> > Moreover, once when the new protocol is used, we can use the standard
> >> > 64bit monotonic nsecs as a timestamp, so that we don't need to care
> >> > about 32/64bit compatibility.
> >>
> >> I think that's fine, we can do that too, but I don't see how we get around
> >> to doing something like Baolin's patch first. Without this, we will get
> >> existing user space code compiling against our kernel headers using a
> >> new glibc release that will inadvertently change the structure layout
> >> on the read file descriptor.
> >
> > But it won't work in anyway in multiple ways, e.g. this timer read
> > stuff and another the structs embedded in the mmappged page.  If you
> > do rebuild things with new glibc, it should tell kernel about the new
> > ABI in anyway more or less explicitly.  And if you need it, it means
> > that some source-code level API change would be possible.
> 
> Right, you mentioned the mmap interface at the kernel summit. This
> is certainly the most tricky part and will probably require source-level
> changes.
> 
> Can you clarify a few things about the mmap() interface?
> Is this specifically about "struct snd_pcm_mmap_status" on the
> pcm device, or are there others?
> 
> From what I can see, it's already fairly limited:
> - on most architectures, it's completely disabled, only x86, ppc and
>   alpha allow it to start with, and user space can work around
>   the mmap not being available by falling back to ioctl if I read
>   the comments correctly
> - alpha is not affected since time_t is always 64-bit
> - x86 and ppc disable the mmap() in compat mode already because
>   of the same issue. If it comes to the worst, we can probably do
>   the same for x86-32 and ppc32, disabling the existing status mmap
>   for them as well, and change SNDRV_PCM_MMAP_OFFSET_STATUS
>   to a new value for 32-bit kernels that exposes the same structure
>   as 64-bit kernels.
> - I think that since we always use an offset that is defined in the
>   header file, we can use the same trick for mmap that we have
>   for the ioctl command number:
> 
> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
> index c227ccba60ae..bcdbdac097d9 100644
> --- a/include/uapi/sound/asound.h
> +++ b/include/uapi/sound/asound.h
> @@ -306,10 +306,19 @@ typedef int __bitwise snd_pcm_state_t;
> 
>  enum {
>         SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000,
> -       SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000,
> +       SNDRV_PCM_MMAP_OFFSET_STATUS_OLD = 0x80000000,
>         SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000,
> +       SNDRV_PCM_MMAP_OFFSET_STATUS64 = 0x82000000,
>  };
> 
> +#if __BITS_PER_LONG == 64
> +#define SNDRV_PCM_MMAP_OFFSET_STATUS SNDRV_PCM_MMAP_OFFSET_STATUS_OLD
> +#else
> +#define SNDRV_PCM_MMAP_OFFSET_STATUS ((sizeof(time_t) >
> sizeof(__kernel_long_t)) ? \
> +                                       SNDRV_PCM_MMAP_OFFSET_STATUS64 : \
> +                                       SNDRV_PCM_MMAP_OFFSET_STATUS_OLD)
> +#endif
> +
>  union snd_pcm_sync_id {
>         unsigned char id[16];
>         unsigned short id16[8];
> 
> Does that make sense?

Yeah, that should work.

But can we make the flip without the dynamic sizeof() comparison but
some ifdef?  The above doesn't allow the usage with switch(), for
example.

IOW, is there any macro indicating the 64bit user time_t?

In theory we can have the shadow mmap for the compat timespec, and
convert it always when the status gets changed.  But I guess disabling
the mmap should work simply as is, judging from the 64bit compat
status.


So, basically speaking, I find all fine with the suggested
conversions.  But, some details look fairly ugly, like the dynamic
const evaluation in the above.  If we can tidy up these devils, the
code will become more readable.


thanks,

Takashi

  reply	other threads:[~2017-11-09 16:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 11:06 [RFC PATCH v2 0/7] Fix year 2038 issue for sound subsystem Baolin Wang
2017-11-02 11:06 ` [RFC PATCH v2 1/7] sound: Replace timespec with timespec64 Baolin Wang
2017-11-02 11:06 ` [RFC PATCH v2 2/7] sound: core: Avoid using timespec for struct snd_pcm_status Baolin Wang
2017-11-05 10:23   ` [alsa-devel] " Takashi Iwai
2017-11-05 10:23     ` Takashi Iwai
2017-11-05 13:48     ` [alsa-devel] " Arnd Bergmann
2017-11-02 11:06 ` [RFC PATCH v2 3/7] sound: core: Avoid using timespec for struct snd_rawmidi_status Baolin Wang
2017-11-02 11:06 ` [RFC PATCH v2 4/7] sound: core: Avoid using timespec for struct snd_timer_status Baolin Wang
2017-11-02 11:06 ` [RFC PATCH v2 5/7] uapi: sound: Avoid using timespec for struct snd_ctl_elem_value Baolin Wang
2017-11-08 13:44   ` Takashi Sakamoto
2017-11-08 13:44     ` Takashi Sakamoto
2017-11-02 11:06 ` [RFC PATCH v2 6/7] sound: core: Avoid using timespec for struct snd_pcm_sync_ptr Baolin Wang
2017-11-02 11:06 ` [RFC PATCH v2 7/7] sound: core: Avoid using timespec for struct snd_timer_tread Baolin Wang
2017-11-05 10:29   ` [alsa-devel] " Takashi Iwai
2017-11-05 13:16     ` Arnd Bergmann
2017-11-05 16:59       ` Takashi Iwai
2017-11-05 16:59         ` Takashi Iwai
2017-11-06 16:33         ` [alsa-devel] " Arnd Bergmann
2017-11-09 16:52           ` Takashi Iwai [this message]
2017-11-09 16:52             ` Takashi Iwai
2017-11-09 17:01             ` [alsa-devel] " Arnd Bergmann
2017-11-09 17:01               ` Arnd Bergmann
2017-11-09 18:11               ` [alsa-devel] " Takashi Iwai
2017-11-09 18:11                 ` Takashi Iwai
2017-11-09 23:20                 ` [alsa-devel] " Arnd Bergmann
2017-11-10  7:19                   ` Takashi Iwai
2017-11-10  7:19                     ` 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=s5h1sl7e6np.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=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=subhransu.s.prusty@intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.