Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Jiri Slaby

On 01/29/2008 02:18 PM, Yoav Artzi wrote:
Thanks. I am aware of these issues and we already have a pretty capable 
layer to deal with these issues (unfortunately, it was very necessary). 
My problem is not with the data carried by the IOCTL, but with IOCTL 
command code itself, which comes out wrong on the kernel side. And my 
problem is not only in the size data, but also in other fields.


IOCTL command code:

1 byte: W/R/RW    Passes 
through fine


1 byte: size of data carried  DOESN'T 
PASS THROUGH


1 byte: identifier character of the module    Passes through fine

1 byte: IOCTL number    DOESN'T PASS 
THROUGH



The funny thing is that I always get the same IOCTL command code on the 
kernel side, no matter what I send using the ioctl() system call.



Any idea?


Please show us your code with ioctls implemented both in kernel and userspace. 
And the definitions and fops aswell. Without it it's very hard to say what's 
going wrong.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Jiri Slaby

On 01/29/2008 02:05 PM, Michael Tokarev wrote:

(And try to avoid such types there, use u32 or u64 and the like
that explicitly specify size).


... and don't pass pointers to _IOC macros as well.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Matti Aarnio
On Tue, Jan 29, 2008 at 02:13:26PM +0200, Yoav Artzi wrote:
> Hi,
>
>
> I have a 32-bit user land application which sends an IOCTL to a 64-bit 
> Kernel module. I have a few different cmd codes that I can send through the 
> IOCTL. For some reason I seem to always get the same IOCTL cmd from user 
> land, no matter what the ioctl() call is given. This cmd code that I get 
> has some bytes (W/R and the module code) that are OK, but the rest is just 
> garbage or zeros. This was originally a 32-bit system, and we are no 
> converting the Kernel module to 64-bit, so maybe there's something special 
> for 32-64 communication that miss.

In x86_64 kernel there is an adaptation layer that translates 32-bit ioctl:s
to kernel internal 64-bit ones, when absolutely necessary.

If you do not need to pass pointers in your ioctl(), then typedef:in passed
parameters with explicite size may save you from lots of trouble:

   struct cpioctl {
long var;   /* definite trouble 32-bit vs. 64-bit */
uint32_t var2;  /* no troubles... */
uint64_t var3;
   };

After that, the only issue is that 32-bit user space ioctl() passes
a pointer that is valid in 32-bit space only, bit that is handled by
the common layer without need to make specific adaptation routine.

.. however if the structure has pointer to elsewere in memory, then
things get complicated really fast.


> I am working on Linux Kernel v2.6.18.
> Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Yoav Artzi
Thanks. I am aware of these issues and we already have a pretty capable 
layer to deal with these issues (unfortunately, it was very necessary). 
My problem is not with the data carried by the IOCTL, but with IOCTL 
command code itself, which comes out wrong on the kernel side. And my 
problem is not only in the size data, but also in other fields.


IOCTL command code:

1 byte: W/R/RW    Passes 
through fine


1 byte: size of data carried  DOESN'T 
PASS THROUGH


1 byte: identifier character of the module    Passes through fine

1 byte: IOCTL number    DOESN'T PASS 
THROUGH



The funny thing is that I always get the same IOCTL command code on the 
kernel side, no matter what I send using the ioctl() system call.



Any idea?


Thanks


 Original Message  

Subject: Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module
From: Michael Tokarev <[EMAIL PROTECTED]>
To: Yoav Artzi <[EMAIL PROTECTED]>
Date: Tuesday, January 29, 2008 3:05:01 PM


Yoav Artzi wrote:
 

Hi,


I have a 32-bit user land application which sends an IOCTL to a 64-bit
Kernel module. I have a few different cmd codes that I can send through
the IOCTL. For some reason I seem to always get the same IOCTL cmd from
user land, no matter what the ioctl() call is given. This cmd code that
I get has some bytes (W/R and the module code) that are OK, but the rest
is just garbage or zeros. This was originally a 32-bit system, and we
are no converting the Kernel module to 64-bit, so maybe there's
something special for 32-64 communication that miss.



Please see numerous examples in kernel source, in many files named
compat_ioctl.c.  If your ioctls uses structures with fields that
have different sizes in 32- and 64-bit worlds (most notable int,
various enums etc), there should be corresponding translation
layer as in those examples.  If it's your kernel code, that is.
(And try to avoid such types there, use u32 or u64 and the like
that explicitly specify size).

Another possible problem is different alignment of fields in
64- vs 32-bits worlds.

 

I am working on Linux Kernel v2.6.18.



If the kernel side isn't your code, the chances are quite high
that this problem has long been fixed in more recent kernels.

/mjt

Scanned by Check Point Total Security Gateway.

  



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Yoav Artzi

Hi,


I have a 32-bit user land application which sends an IOCTL to a 64-bit 
Kernel module. I have a few different cmd codes that I can send through 
the IOCTL. For some reason I seem to always get the same IOCTL cmd from 
user land, no matter what the ioctl() call is given. This cmd code that 
I get has some bytes (W/R and the module code) that are OK, but the rest 
is just garbage or zeros. This was originally a 32-bit system, and we 
are no converting the Kernel module to 64-bit, so maybe there's 
something special for 32-64 communication that miss.



I am working on Linux Kernel v2.6.18.


Thanks


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Michael Tokarev
Yoav Artzi wrote:
> Hi,
> 
> 
> I have a 32-bit user land application which sends an IOCTL to a 64-bit
> Kernel module. I have a few different cmd codes that I can send through
> the IOCTL. For some reason I seem to always get the same IOCTL cmd from
> user land, no matter what the ioctl() call is given. This cmd code that
> I get has some bytes (W/R and the module code) that are OK, but the rest
> is just garbage or zeros. This was originally a 32-bit system, and we
> are no converting the Kernel module to 64-bit, so maybe there's
> something special for 32-64 communication that miss.

Please see numerous examples in kernel source, in many files named
compat_ioctl.c.  If your ioctls uses structures with fields that
have different sizes in 32- and 64-bit worlds (most notable int,
various enums etc), there should be corresponding translation
layer as in those examples.  If it's your kernel code, that is.
(And try to avoid such types there, use u32 or u64 and the like
that explicitly specify size).

Another possible problem is different alignment of fields in
64- vs 32-bits worlds.

> I am working on Linux Kernel v2.6.18.

If the kernel side isn't your code, the chances are quite high
that this problem has long been fixed in more recent kernels.

/mjt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Sending IOCTLs from 32-bit userland to 64-bit Kernel module

2008-01-29 Thread Yoav Artzi

Hi,


I have a 32-bit user land application which sends an IOCTL to a 64-bit 
Kernel module. I have a few different cmd codes that I can send through 
the IOCTL. For some reason I seem to always get the same IOCTL cmd from 
user land, no matter what the ioctl() call is given. This cmd code that 
I get has some bytes (W/R and the module code) that are OK, but the rest 
is just garbage or zeros. This was originally a 32-bit system, and we 
are no converting the Kernel module to 64-bit, so maybe there's 
something special for 32-64 communication that miss.



I am working on Linux Kernel v2.6.18.


Thanks

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/