Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ALSA and dmix with a 32bit process
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
367090
n00b
n00b


Joined: 20 May 2017
Posts: 3

PostPosted: Wed May 24, 2017 1:45 pm    Post subject: ALSA and dmix with a 32bit process Reply with quote

After almost 2 years of using Linux (last 6 months on Gentoo), I stumbled into a problem I can't fix on my own, I hope you can help me out or at least point me in the right direction.

I use ALSA w/o PulseAudio, ALSA is compiled with abi_x86_32 use flag which is required for win32 Wine prefixes. I use neither .asoundrc nor a custom asound.conf.
With the default configuration, audio from a win32 Wine prefix and a 64bit application is correctly mixed (dmix). I tested this with Audacious, aplay, Firefox and many others.

However, a week ago alsa-lib and related packages were bumped from 1.1.3 to 1.1.4. With the update, mixing no longer work. If a Wine 32-bit application is run first, then all other applications no longer have audio and vice-versa.
The error I get is:
Code:
ALSA lib pcm_dmix.c:1077:(snd_pcm_dmix_open) unable to create IPC shm instance


I ran an strace on aplay test.wav for 3 different cases: no Wine application running, 64-bit Wine application running and 32-bit Wine application running. The logs are pretty long so I'll just report what I think is the relevant part:

With no Wine application running, shmget doesn't get a shared memory segment (it doesn't exist yet), so one is created. I can hear aplay output.
Code:
semget(0x56a4d5, 1, IPC_CREAT|0660)     = 1212416
semctl(1212416, 0, IPC_STAT, 0x7ffc530d6740) = 0
semctl(1212416, 0, IPC_SET, 0x7ffc530d6740) = 0
semop(1212416, [{0, 0, 0}, {0, 1, SEM_UNDO}], 2) = 0
shmget(0x56a4d5, 496, 0660)             = -1 ENOENT (No such file or directory)
shmget(0x56a4d5, 496, IPC_CREAT|IPC_EXCL|0660) = 2949126
shmat(2949126, NULL, 0)                 = 0x7f0f064ea000
mlock(0x7f0f064ea000, 496)              = 0


With a 64-bit Wine application running, shmget gets the existing shared memory segment. I can hear aplay output.
Code:
semget(0x56a4d5, 1, IPC_CREAT|0660)     = 851968
semctl(851968, 0, IPC_STAT, 0x7ffec5a559d0) = 0
semctl(851968, 0, IPC_SET, 0x7ffec5a559d0) = 0
semop(851968, [{0, 0, 0}, {0, 1, SEM_UNDO}], 2) = 0
shmget(0x56a4d5, 496, 0660)             = 2293769
shmat(2293769, NULL, 0)                 = 0x7f14c5d16000
mlock(0x7f14c5d16000, 496)              = 0


With a 32-bit Wine application running, shmget doesn't get the shared memory segment because it's invalid. No sound and aplay prints an error.
Code:
semget(0x56a4d5, 1, IPC_CREAT|0660)     = 1179648
semctl(1179648, 0, IPC_STAT, 0x7ffeb4b0c360) = 0
semctl(1179648, 0, IPC_SET, 0x7ffeb4b0c360) = 0
semop(1179648, [{0, 0, 0}, {0, 1, SEM_UNDO}], 2) = 0
shmget(0x56a4d5, 496, 0660)             = -1 EINVAL (Invalid argument)
shmget(0x56a4d5, 0, 0660)               = 2883592
shmctl(2883592, IPC_STAT, {shm_perm={uid=1000, gid=18, mode=0660, key=5678293, cuid=1000, cgid=1000}, shm_segsz=492, shm_cpid=3354, shm_lpid=3354, shm_nattch=1, shm_atime=1495290474, shm_dtime=0, shm_ctime=1495290474}) = 0
write(2, "ALSA lib /var/tmp/portage/media-"..., 116ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.4/work/alsa-lib-1.1.4/src/pcm/pcm_dmix.c:1077:(snd_pcm_dmix_open) ) = 116
write(2, "unable to create IPC shm instanc"..., 33unable to create IPC shm instance) = 33
write(2, "\n", 1
)                       = 1


In the kernel manual, for shmget error values, it says:
Code:

EINVAL A new segment was to be created and size is less than SHMMIN
              or greater than SHMMAX.
EINVAL A segment for the given key exists, but size is greater than
              the size of that segment.


I think it's the second one but I don't know what to do with this information.

I googled for similar problems but I didn't find much. I also tried to read the ALSA documentation but I can't figure it out.

Unfortunately, I don't have the skill/time to figure out what commit between 1.1.3 and 1.1.4 causes the problem but if I had to guess I would say it's this one.

Of course, I could just mask alsa-lib-1.1.4 and alsa-utils-1.1.4, but eventually I'll have to unmask it. I hope the solution is not to install PulseAudio.
Back to top
View user's profile Send private message
infinigon
n00b
n00b


Joined: 24 May 2017
Posts: 2

PostPosted: Wed May 24, 2017 7:33 pm    Post subject: Reply with quote

Encountered the same bug on Arch Linux today, with exactly the same use case.

I've bisected the commit that the bug was introduced in, and sent a bug report to the alsa-devel mailing list. I'll keep you informed if/when the bug gets fixed.

http://mailman.alsa-project.org/pipermail/alsa-devel/2017-May/121055.html
Back to top
View user's profile Send private message
367090
n00b
n00b


Joined: 20 May 2017
Posts: 3

PostPosted: Thu May 25, 2017 10:02 pm    Post subject: Reply with quote

I've been following your exchange with Takashi Iwai on the mailing list and it seems you guys figured it out.
For now I am going to unmask and use your padding patch which has fixed the problem for me.
Thank you very much for your help.

For other Gentoo users, put this in /etc/portage/patches/media-libs/alsa-lib-1.1.4/dmix-padding.patch to fix the issue:
Code:
--- alsa-lib-1.1.4/src/pcm/pcm_direct.h   2017-05-12 10:01:45.000000000 +0200
+++ /tmp/pcm_direct.h   2017-05-25 23:38:44.280687121 +0200
@@ -61,7 +61,7 @@
 };
 
 /* shared among direct plugin clients - be careful to be 32/64bit compatible! */
-typedef struct {
+typedef struct __attribute__((packed)) {
    unsigned int magic;         /* magic number */
    char socket_name[256];         /* name of communication socket */
    snd_pcm_type_t type;         /* PCM type (currently only hw) */
Back to top
View user's profile Send private message
infinigon
n00b
n00b


Joined: 24 May 2017
Posts: 2

PostPosted: Sun Jun 04, 2017 2:58 am    Post subject: Reply with quote

A bit late, but alsa-lib v1.1.4.1 was released with the fix.
Back to top
View user's profile Send private message
TechwoIf
n00b
n00b


Joined: 06 Aug 2007
Posts: 38

PostPosted: Thu Jun 22, 2017 11:44 pm    Post subject: Reply with quote

How do you copy/paste the patch? I tried it and patch fails with:
Code:

* Messages for package media-libs/alsa-lib-1.1.4:

 * ERROR: media-libs/alsa-lib-1.1.4::gentoo failed (prepare phase):
 *   patch -p1  failed with /etc/portage/patches/media-libs/alsa-lib-1.1.4/dmix-padding.patch


[Moderator edit: added [code] tags to preserve output layout. -Hu]
Back to top
View user's profile Send private message
Chiitoo
Administrator
Administrator


Joined: 28 Feb 2010
Posts: 2575
Location: Here and Away Again

PostPosted: Thu Jun 22, 2017 11:50 pm    Post subject: ><)))°€ Reply with quote

TechwoIf,

Any reason you can't go for 1.1.4.1?
_________________
Kindest of regardses.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Fri Jun 23, 2017 1:20 am    Post subject: Reply with quote

TechwoIf wrote:
How do you copy/paste the patch?
I think the more pertinent question is how did you copy it and how did you place it in the local file? If you need help getting the patch to work, you need to show us more than a generic failure report. What is the output of xxd /etc/portage/patches/media-libs/alsa-lib-1.1.4/dmix-padding.patch (requires app-editors/vim-core)?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum