All of lore.kernel.org
 help / color / mirror / Atom feed
* kmalloc - Address is not consecutive
@ 2021-08-19 10:54 Lloyd
  2021-08-19 12:16 ` wuzhouhui
  0 siblings, 1 reply; 4+ messages in thread
From: Lloyd @ 2021-08-19 10:54 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 686 bytes --]

Hi,

I am trying to print the address of consecutive locations in a
memory allocated using kmalloc. It prints non contiguous addresses! I tried
with kmalloc_array, and  normal array on stack, I got the same  result. May
I know the reason? The code fragment for array and result are given below.

uint8_t MyArray[100]={'0'};
printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]);
printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]);
printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);


[ 8684.613909]               Address is-> 00000000b3330991
[ 8684.613914]               Address is-> 000000000519068c
[ 8684.613915]               Address is-> 00000000e448ca76


Thanks a lot,
  Lloyd

[-- Attachment #1.2: Type: text/html, Size: 2600 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: kmalloc - Address is not consecutive
  2021-08-19 10:54 kmalloc - Address is not consecutive Lloyd
@ 2021-08-19 12:16 ` wuzhouhui
  2021-08-19 13:29   ` ckim
       [not found]   ` <E1mGi6z-0002zV-NE@shelob.surriel.com>
  0 siblings, 2 replies; 4+ messages in thread
From: wuzhouhui @ 2021-08-19 12:16 UTC (permalink / raw)
  To: Lloyd, kernelnewbies



On 8/19/21 6:54 PM, Lloyd wrote:
> Hi,
>
> I am trying to print the address of consecutive locations in a 
> memory allocated using kmalloc. It prints non contiguous addresses! I 
> tried with kmalloc_array, and  normal array on stack, I got the same  
> result. May I know the reason? The code fragment for array and result 
> are given below.
>
> uint8_t MyArray[100]={'0'};
> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]);
> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]);
> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);
>
>
> [ 8684.613909]               Address is-> 00000000b3330991
> [ 8684.613914]               Address is-> 000000000519068c
> [ 8684.613915]               Address is-> 00000000e448ca76
>
Quoted from Documentation/core-api/printk-formats.rst:
> A raw pointer value may be printed with %p which will hash the address
> before printing. The kernel also supports extended specifiers for printing
> pointers of different types.
So the address printed neither logical nor physical address.

> Thanks a lot,
>   Lloyd
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: kmalloc - Address is not consecutive
  2021-08-19 12:16 ` wuzhouhui
@ 2021-08-19 13:29   ` ckim
       [not found]   ` <E1mGi6z-0002zV-NE@shelob.surriel.com>
  1 sibling, 0 replies; 4+ messages in thread
From: ckim @ 2021-08-19 13:29 UTC (permalink / raw)
  To: wuzhouhui, Lloyd, kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1833 bytes --]

Hi! this one is easy :)For printing pointer in kernel space, you should use %px  not %p as format specifier. I heard this is for security reason(?).Chan Kim내 Galaxy에서 보냄
-------- 원본 이메일 --------발신: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> 날짜: 21/8/19  오후 9:17  (GMT+09:00) 받은 사람: Lloyd <lloydkl.tech@gmail.com>, kernelnewbies@kernelnewbies.org 제목: Re: kmalloc - Address is not consecutive On 8/19/21 6:54 PM, Lloyd wrote:> Hi,>> I am trying to print the address of consecutive locations in a > memory allocated using kmalloc. It prints non contiguous addresses! I > tried with kmalloc_array, and  normal array on stack, I got the same  > result. May I know the reason? The code fragment for array and result > are given below.>> uint8_t MyArray[100]={'0'};> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]);> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]);> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);>>> [ 8684.613909]               Address is-> 00000000b3330991> [ 8684.613914]               Address is-> 000000000519068c> [ 8684.613915]               Address is-> 00000000e448ca76>Quoted from Documentation/core-api/printk-formats.rst:> A raw pointer value may be printed with %p which will hash the address> before printing. The kernel also supports extended specifiers for printing> pointers of different types.So the address printed neither logical nor physical address.> Thanks a lot,>   Lloyd>>> _______________________________________________> Kernelnewbies mailing list> Kernelnewbies@kernelnewbies.org> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies_______________________________________________Kernelnewbies mailing listKernelnewbies@kernelnewbies.orghttps://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[-- Attachment #1.2: Type: text/html, Size: 2741 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: kmalloc - Address is not consecutive
       [not found]   ` <E1mGi6z-0002zV-NE@shelob.surriel.com>
@ 2021-08-19 13:33     ` Lloyd
  0 siblings, 0 replies; 4+ messages in thread
From: Lloyd @ 2021-08-19 13:33 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 2284 bytes --]

Thanks a lot, it worked :)

On Thu, Aug 19, 2021 at 7:00 PM ckim <ckim@etri.re.kr> wrote:

> Hi! this one is easy :)
> For printing pointer in kernel space, you should use %px  not %p as format
> specifier. I heard this is for security reason(?).
> Chan Kim
>
> 내 Galaxy에서 보냄
>
>
> -------- 원본 이메일 --------
> 발신: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
> 날짜: 21/8/19 오후 9:17 (GMT+09:00)
> 받은 사람: Lloyd <lloydkl.tech@gmail.com>, kernelnewbies@kernelnewbies.org
> 제목: Re: kmalloc - Address is not consecutive
>
>
>
> On 8/19/21 6:54 PM, Lloyd wrote:
> > Hi,
> >
> > I am trying to print the address of consecutive locations in a
> > memory allocated using kmalloc. It prints non contiguous addresses! I
> > tried with kmalloc_array, and  normal array on stack, I got the same
> > result. May I know the reason? The code fragment for array and result
> > are given below.
> >
> > uint8_t MyArray[100]={'0'};
> > printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]);
> > printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]);
> > printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);
> >
> >
> > [ 8684.613909]               Address is-> 00000000b3330991
> > [ 8684.613914]               Address is-> 000000000519068c
> > [ 8684.613915]               Address is-> 00000000e448ca76
> >
> Quoted from Documentation/core-api/printk-formats.rst:
> > A raw pointer value may be printed with %p which will hash the address
> > before printing. The kernel also supports extended specifiers for
> printing
> > pointers of different types.
> So the address printed neither logical nor physical address.
>
> > Thanks a lot,
> >   Lloyd
> >
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

[-- Attachment #1.2: Type: text/html, Size: 3854 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2021-08-19 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 10:54 kmalloc - Address is not consecutive Lloyd
2021-08-19 12:16 ` wuzhouhui
2021-08-19 13:29   ` ckim
     [not found]   ` <E1mGi6z-0002zV-NE@shelob.surriel.com>
2021-08-19 13:33     ` Lloyd

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.