ioct32 bit compatibilty questions
Hi,
I'm trying to get ALSA working on my ultra 5 (thatis working with 32 bit userspace). With vanilla 2.6.9 the machine just hangs when running alsa mixer.
After some debugging it seems that some alsa ioctl have a pointer to a userspace pointer in their argument struct. When doing a copy_to_user in the native ioctl to that address (thus directly to the 32bit userspace program while get_fs() = KERNEL_DS), the machine just hangs. Is this something that can't be done on sparc64 ?
I've ``fixed'' the SNDRV_CTL_IOCTL_ELEM_LIST to create a buffer and pass that to userspace in the handler instead of doing it directly in the native ioctl. Is this the right way ?
At least alsamixer is working now :) Some other ioctl have the same problem, that i still need to fix.
Any advice is appreciated :)
Sjoerd
Signature · 2 lines
Any sufficiently advanced technology is indistinguishable from magic. -- Arthur C. Clarke
Quoted 5 lines · On Thu, 11 Nov 2004 12:00:24 +0100 [email protected] (Sjoerd Simons) wrote:
After some debugging it seems that some alsa ioctl have a pointer to a userspace pointer in their argument struct. When doing a
copy_to_userin the native ioctl to that address (thus directly to the 32bit userspace program whileget_fs()=KERNEL_DS), the machine just hangs. Is this something that can't be done on sparc64 ?
That's right, this action is illegal and will hang the machine. Unfortunately, on x86_64 this happens to work and that appears to be where most of the ioctl32 compat stuff gets tested and developed.
If get_fs() = KERNEL_DS all "user" pointers are expected to be in kernel space and thus access to real user addresses will fail.
Quoted 9 lines · David S. Miller
Quoted 5 lines · On Thu, 11 Nov 2004 12:00:24 +0100 [email protected] (Sjoerd Simons) wrote:
After some debugging it seems that some alsa ioctl have a pointer to a userspace pointer in their argument struct. When doing a
copy_to_userin the native ioctl to that address (thus directly to the 32bit userspace program whileget_fs()=KERNEL_DS), the machine just hangs. Is this something that can't be done on sparc64 ?
Quoted 7 lines
That's right, this action is illegal and will hang the machine. Unfortunately, on
x86_64this happens to work and that appears to be where most of the ioctl32 compat stuff gets tested and developed.If
get_fs()=KERNEL_DSall "user" pointers are expected to be in kernel space and thus access to real user addresses will fail.
Finally had time to finish the patch. With alsaplayer there is now music out of my U5's speakers :) Unfortunately there is some distortion. But that is probably the card driver itself. A friend of mine told me he also had distortions with alsa's oss emulation on an U5..
Patch attached against linux 2.6.9. I haven't done a lot of kernel hacking, so any comments are very welcome!
Also for the people interested i've put a patch against alsa cvs in the alsa bug tracking system so they can have a look at it too.
Sjoerd
Signature · 2 lines
You can no more win a war than you can win an earthquake. -- Jeannette Rankin
Quoted 2 lines · Sjoerd Simons
Patch attached against linux 2.6.9. I haven't done a lot of kernel hacking, so any comments are very welcome!
Ofcourse i forgot to actually attach it. Second try :)
Sjoerd
Signature · 3 lines
What is wanted is not the will to believe, but the will to find out, which is the exact opposite. -- Bertrand Russell, "Skeptical Essays", 1928
sound/core/ioctl32/hwdep32.c +15 -1
@@ -40,19 +40,33 @@struct sndrv_hwdep_dsp_image32 data32;mm_segment_t oldseg;int err; +void *image =NULL ;if (copy_from_user (&data32, (void __user *)arg,sizeof (data32)))return -EFAULT ; + image =kmalloc (data32.length,GFP_KERNEL ); +if (image ==NULL ) { + err = -ENOMEM ; + goto __dsp_image_out; + } +if (copy_from_user (image, (void __user *)compat_ptr (data32.image), + data32.length)) { + err = -EFAULT ; + goto __dsp_image_out; + }memset (&data,0 ,sizeof (data)); data.index = data32.index;memcpy (data.name, data32.name,sizeof (data.name)); - data.image =compat_ptr (data32.image); + data.image = image; data.length = data32.length; data.driver_data = data32.driver_data; oldseg =get_fs ();set_fs (KERNEL_DS ); err = file->f_op->ioctl (file->f_dentry->d_inode, file, native_ctl, (unsigned long )&data);set_fs (oldseg); + +__dsp_image_out: +kfree (image);return err; }
sound/core/ioctl32/ioctl32.c +34 -20
115 lines not on this page · raw message
sound/core/ioctl32/ioctl32.h +0 -1
@@ -29,7 +29,6 @@#include <linux/compat.h> #define COPY (x) (dst->x = src->x) -#define CPTR (x) (dst->x = compat_ptr(src->x))#define convert_from_32 (type, dstp, srcp)\ {\
sound/core/ioctl32/pcm32.c +49 -14
126 lines not on this page · raw message
Quoted 2 lines · Sjoerd Simons
Patch attached against linux 2.6.9. I haven't done a lot of kernel hacking, so any comments are very welcome!
For those of you interested in the upstream bug on the alsa bug tracker, check out:
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=167
I've made some comments in there about the patch... and my ens1371 still hangs on alsa playback... so it's not all fixed yet... but if you're interested, please take a look at that bug and followup there so we can keep all of this in one place =)
--Jeremy
Signature · 1 line
Jeremy Huddleston <[email protected]>