linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* 3 version of MKDEV: kernel, uapi, libc, why?
@ 2018-04-11  8:51 Zhang, Ning A
  2018-04-11 10:04 ` gregkh
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang, Ning A @ 2018-04-11  8:51 UTC (permalink / raw)
  To: pombredanne, tglx, gregkh, kstewart; +Cc: linux-kernel

Hi, Greg, Thomas

I find 3 version of MKDEV (actually 2 + makedev)

in include/linux/kdev_t.h

    #define MINORBITS    	    20
    #define MKDEV(ma,mi)    	    (((ma) << MINORBITS) | (mi))

in inlcude/uapi/linux/kdev_t.h

    #define MKDEV(ma,mi)    	    ((ma)<<8 | (mi))

in Android bionic

    #define makedev(__major, __minor) \
      ( \
        (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) <<
    8) | \
        (((__minor) & 0xffffff00ULL) << 12) | (((__minor) & 0xffULL)) \
      )

if I use mknod("renderD128", S_IFCHR|0666, MKDEV(226, 128));
I get wrong device:
crw-rw-rw- 1 root graphics 0, 57984 2011-11-11 11:20 renderD128


if I use ("renderD128",S_IFCHR|0666, makedev(226, 128));
I get right device.

but, when I use: mknod("card0", S_IFCHR|0666, MKDEV(226, 0));
I can get right device.

BR.
Ning.

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

* Re: 3 version of MKDEV: kernel, uapi, libc, why?
  2018-04-11  8:51 3 version of MKDEV: kernel, uapi, libc, why? Zhang, Ning A
@ 2018-04-11 10:04 ` gregkh
  2018-04-12  1:45   ` Zhang, Ning A
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2018-04-11 10:04 UTC (permalink / raw)
  To: Zhang, Ning A; +Cc: pombredanne, tglx, kstewart, linux-kernel

On Wed, Apr 11, 2018 at 08:51:03AM +0000, Zhang, Ning A wrote:
> Hi, Greg, Thomas
> 
> I find 3 version of MKDEV (actually 2 + makedev)
> 
> in include/linux/kdev_t.h
> 
>     #define MINORBITS    	    20
>     #define MKDEV(ma,mi)    	    (((ma) << MINORBITS) | (mi))
> 
> in inlcude/uapi/linux/kdev_t.h
> 
>     #define MKDEV(ma,mi)    	    ((ma)<<8 | (mi))

Isn't history grand :)
Those are different because we increased the size way back in the 2.5
kernel (I think), so we had to do so in a way that did not break
userspace.

> in Android bionic
> 
>     #define makedev(__major, __minor) \
>       ( \
>         (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) <<
>     8) | \
>         (((__minor) & 0xffffff00ULL) << 12) | (((__minor) & 0xffULL)) \
>       )

Fun stuff :)

> if I use mknod("renderD128", S_IFCHR|0666, MKDEV(226, 128));
> I get wrong device:
> crw-rw-rw- 1 root graphics 0, 57984 2011-11-11 11:20 renderD128
> 
> 
> if I use ("renderD128",S_IFCHR|0666, makedev(226, 128));
> I get right device.
> 
> but, when I use: mknod("card0", S_IFCHR|0666, MKDEV(226, 0));
> I can get right device.

Why are you calling 'mknod' at all?  The kernel does this automagically
for you already, in devtmpfs.  You should not have to do this on your
own ever.

Unless you are using a crazy Android system that doesn't use that
filesystem.  And if you are, go complain to those developers about it,
not much we can do from within the kernel.

And the answer is yes, use the right macro, for when you want to really
do this.  Your libc should provide the correct one, trust it.

good luck!

greg k-h

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

* Re: 3 version of MKDEV: kernel, uapi, libc, why?
  2018-04-11 10:04 ` gregkh
@ 2018-04-12  1:45   ` Zhang, Ning A
  0 siblings, 0 replies; 3+ messages in thread
From: Zhang, Ning A @ 2018-04-12  1:45 UTC (permalink / raw)
  To: gregkh; +Cc: pombredanne, tglx, linux-kernel, kstewart

[-- Attachment #1: Type: text/plain, Size: 2164 bytes --]

Thank you for the answers.

在 2018-04-11三的 12:04 +0200,gregkh@linuxfoundation.org写道:

On Wed, Apr 11, 2018 at 08:51:03AM +0000, Zhang, Ning A wrote:


Hi, Greg, Thomas

I find 3 version of MKDEV (actually 2 + makedev)

in include/linux/kdev_t.h

    #define MINORBITS               20
    #define MKDEV(ma,mi)            (((ma) << MINORBITS) | (mi))

in inlcude/uapi/linux/kdev_t.h

    #define MKDEV(ma,mi)            ((ma)<<8 | (mi))



Isn't history grand :)
Those are different because we increased the size way back in the 2.5
kernel (I think), so we had to do so in a way that did not break
userspace.


so two versions of MKDEV will be kept in source code?





in Android bionic

    #define makedev(__major, __minor) \
      ( \
        (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) <<
    8) | \
        (((__minor) & 0xffffff00ULL) << 12) | (((__minor) & 0xffULL)) \
      )



Fun stuff :)



if I use mknod("renderD128", S_IFCHR|0666, MKDEV(226, 128));
I get wrong device:
crw-rw-rw- 1 root graphics 0, 57984 2011-11-11 11:20 renderD128


if I use ("renderD128",S_IFCHR|0666, makedev(226, 128));
I get right device.

but, when I use: mknod("card0", S_IFCHR|0666, MKDEV(226, 0));
I can get right device.



Why are you calling 'mknod' at all?  The kernel does this automagically
for you already, in devtmpfs.  You should not have to do this on your
own ever.

Unless you are using a crazy Android system that doesn't use that
filesystem.  And if you are, go complain to those developers about it,
not much we can do from within the kernel.

And the answer is yes, use the right macro, for when you want to really
do this.  Your libc should provide the correct one, trust it.


Android doesn't use kdevtmpfs.
I think this mainly because SELinux, device UID/GID and mode.
Android ueventd will create devices nodes with SELinux label, and set right UID/GID, mode according to uevent.rc

kdevtmpfs doesn't support these 3 features.

uses kdevtmpfs is an idea in my mind to optimize Android cold boot.

BR.
Ning.


good luck!

greg k-h


[-- Attachment #2: Type: text/html, Size: 2893 bytes --]

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

end of thread, other threads:[~2018-04-12  1:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-11  8:51 3 version of MKDEV: kernel, uapi, libc, why? Zhang, Ning A
2018-04-11 10:04 ` gregkh
2018-04-12  1:45   ` Zhang, Ning A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).