All of lore.kernel.org
 help / color / mirror / Atom feed
* question about V4L2_MEMORY_USERPTR on 64bit applications
@ 2018-10-12  3:04 Zhang, Ning A
  2018-10-12  3:25 ` Bing Bu Cao
  2018-10-12  4:33 ` Zhang, Ning A
  0 siblings, 2 replies; 5+ messages in thread
From: Zhang, Ning A @ 2018-10-12  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-media

Hi,

I have question about V4L2_MEMORY_USERPTR on 64bit applications.

struct v4l2_buffer {
	__u32			index;
	__u32			type;
	__u32			bytesused;
	__u32			flags;
	__u32			field;
	struct timeval		timestamp;
	struct v4l2_timecode	timecode;
	__u32			sequence;

	/* memory location */
	__u32			memory;
	union {
		__u32           offset;
		unsigned long   userptr;   <<<--- this is a 32bit addr.
		struct v4l2_plane *planes;
		__s32		fd;
	} m;
	__u32			length;
	__u32			reserved2;
	__u32			reserved;
};

when use a 64bit application, memory from malloc is 64bit address.
memory from GPU (eg, intel i915) are also 64bit address.

when use these kind of memory as V4L2_MEMORY_USERPTR, address will be
truncated into 32bit.

this would be error, but actually not. I really don't understand.

BR.
Ning.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about V4L2_MEMORY_USERPTR on 64bit applications
  2018-10-12  3:04 question about V4L2_MEMORY_USERPTR on 64bit applications Zhang, Ning A
@ 2018-10-12  3:25 ` Bing Bu Cao
  2018-10-12  4:33 ` Zhang, Ning A
  1 sibling, 0 replies; 5+ messages in thread
From: Bing Bu Cao @ 2018-10-12  3:25 UTC (permalink / raw)
  To: Zhang, Ning A, linux-kernel, linux-media

Hi, Ning,

unsigned long   userptr; <<<--- this is a 32bit addr.

I think it's wrong here,for LP64 data modelmachine(unix-like systems), the
actual size ofdata type 'unsigned long'is 8(64bits value)whichis equal
to pointer.
 

On 10/12/2018 11:04 AM, Zhang, Ning A wrote:
> Hi,
>
> I have question about V4L2_MEMORY_USERPTR on 64bit applications.
>
> struct v4l2_buffer {
> 	__u32			index;
> 	__u32			type;
> 	__u32			bytesused;
> 	__u32			flags;
> 	__u32			field;
> 	struct timeval		timestamp;
> 	struct v4l2_timecode	timecode;
> 	__u32			sequence;
>
> 	/* memory location */
> 	__u32			memory;
> 	union {
> 		__u32           offset;
> 		unsigned long   userptr;   <<<--- this is a 32bit addr.
> 		struct v4l2_plane *planes;
> 		__s32		fd;
> 	} m;
> 	__u32			length;
> 	__u32			reserved2;
> 	__u32			reserved;
> };
>
> when use a 64bit application, memory from malloc is 64bit address.
> memory from GPU (eg, intel i915) are also 64bit address.
>
> when use these kind of memory as V4L2_MEMORY_USERPTR, address will be
> truncated into 32bit.
>
> this would be error, but actually not. I really don't understand.
>
> BR.
> Ning.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about V4L2_MEMORY_USERPTR on 64bit applications
  2018-10-12  3:04 question about V4L2_MEMORY_USERPTR on 64bit applications Zhang, Ning A
  2018-10-12  3:25 ` Bing Bu Cao
@ 2018-10-12  4:33 ` Zhang, Ning A
  2018-10-12  5:22   ` tbhardwa
  1 sibling, 1 reply; 5+ messages in thread
From: Zhang, Ning A @ 2018-10-12  4:33 UTC (permalink / raw)
  To: linux-kernel, linux-media

sorry for wrong question, I really meet memory address truncated issue,
when use V4L2 kernel APIs.

in a kernel thread created by kernel_thread()
I vm_mmap a shmem_file to addr: 00007ffff7fa8000
and queue it to V4L2, after dequeue it, and I find the address is
truncated to 00000000f7fa8000

I use __u64 {aka long long unsigned int} to save address, and I find
userptr is unsigned long, wrongly think it as "data truncated"
and a lot of __u32 in this structure.

everything works fine, but I still don't understand why high 32bit be
0..

BR.
Ning.


在 2018-10-12五的 11:04 +0800,Zhang Ning写道:
> Hi,
> 
> I have question about V4L2_MEMORY_USERPTR on 64bit applications.
> 
> struct v4l2_buffer {
> 	__u32			index;
> 	__u32			type;
> 	__u32			bytesused;
> 	__u32			flags;
> 	__u32			field;
> 	struct timeval		timestamp;
> 	struct v4l2_timecode	timecode;
> 	__u32			sequence;
> 
> 	/* memory location */
> 	__u32			memory;
> 	union {
> 		__u32           offset;
> 		unsigned long   userptr;   <<<--- this is a 32bit addr.
> 		struct v4l2_plane *planes;
> 		__s32		fd;
> 	} m;
> 	__u32			length;
> 	__u32			reserved2;
> 	__u32			reserved;
> };
> 
> when use a 64bit application, memory from malloc is 64bit address.
> memory from GPU (eg, intel i915) are also 64bit address.
> 
> when use these kind of memory as V4L2_MEMORY_USERPTR, address will be
> truncated into 32bit.
> 
> this would be error, but actually not. I really don't understand.
> 
> BR.
> Ning.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: question about V4L2_MEMORY_USERPTR on 64bit applications
  2018-10-12  4:33 ` Zhang, Ning A
@ 2018-10-12  5:22   ` tbhardwa
  2018-10-14  0:11     ` Eugene Syromiatnikov
  0 siblings, 1 reply; 5+ messages in thread
From: tbhardwa @ 2018-10-12  5:22 UTC (permalink / raw)
  To: 'Zhang, Ning A', linux-kernel, linux-media

64 bit kernel have 64 bit long(not 32 bit), which is not the case with userspace (in 64 bit userspace long is 32-bit). Probably thig got you confused.

-----Original Message-----
From: linux-media-owner@vger.kernel.org <linux-media-owner@vger.kernel.org> On Behalf Of Zhang, Ning A
Sent: Friday, October 12, 2018 10:03 AM
To: linux-kernel@vger.kernel.org; linux-media@vger.kernel.org
Subject: Re: question about V4L2_MEMORY_USERPTR on 64bit applications

sorry for wrong question, I really meet memory address truncated issue, when use V4L2 kernel APIs.

in a kernel thread created by kernel_thread() I vm_mmap a shmem_file to addr: 00007ffff7fa8000 and queue it to V4L2, after dequeue it, and I find the address is truncated to 00000000f7fa8000

I use __u64 {aka long long unsigned int} to save address, and I find userptr is unsigned long, wrongly think it as "data truncated"
and a lot of __u32 in this structure.

everything works fine, but I still don't understand why high 32bit be 0..

BR.
Ning.


在 2018-10-12五的 11:04 +0800,Zhang Ning写道:
> Hi,
> 
> I have question about V4L2_MEMORY_USERPTR on 64bit applications.
> 
> struct v4l2_buffer {
> 	__u32			index;
> 	__u32			type;
> 	__u32			bytesused;
> 	__u32			flags;
> 	__u32			field;
> 	struct timeval		timestamp;
> 	struct v4l2_timecode	timecode;
> 	__u32			sequence;
> 
> 	/* memory location */
> 	__u32			memory;
> 	union {
> 		__u32           offset;
> 		unsigned long   userptr;   <<<--- this is a 32bit addr.
> 		struct v4l2_plane *planes;
> 		__s32		fd;
> 	} m;
> 	__u32			length;
> 	__u32			reserved2;
> 	__u32			reserved;
> };
> 
> when use a 64bit application, memory from malloc is 64bit address.
> memory from GPU (eg, intel i915) are also 64bit address.
> 
> when use these kind of memory as V4L2_MEMORY_USERPTR, address will be 
> truncated into 32bit.
> 
> this would be error, but actually not. I really don't understand.
> 
> BR.
> Ning.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about V4L2_MEMORY_USERPTR on 64bit applications
  2018-10-12  5:22   ` tbhardwa
@ 2018-10-14  0:11     ` Eugene Syromiatnikov
  0 siblings, 0 replies; 5+ messages in thread
From: Eugene Syromiatnikov @ 2018-10-14  0:11 UTC (permalink / raw)
  To: tbhardwa; +Cc: 'Zhang, Ning A', linux-kernel, linux-media

On Fri, Oct 12, 2018 at 10:52:51AM +0530, tbhardwa@codeaurora.org wrote:
> (in 64 bit userspace long is 32-bit)

Not on Linux.

$ cat /tmp/c.c
int main(void)
{
        return sizeof(long);
}
$ gcc /tmp/c.c
$ ./a.out; echo $?
8
$ file ./a.out
./a.out: ELF 64-bit LSB pie executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked, interpreter /lib64/ld64.so.2, for GNU/Linux 3.10.0, BuildID[sha1]=dad78822e741b7900dc7568222822d5d63c31a6c, not stripped

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-14  0:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12  3:04 question about V4L2_MEMORY_USERPTR on 64bit applications Zhang, Ning A
2018-10-12  3:25 ` Bing Bu Cao
2018-10-12  4:33 ` Zhang, Ning A
2018-10-12  5:22   ` tbhardwa
2018-10-14  0:11     ` Eugene Syromiatnikov

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.