From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: ** X-Spam-Status: No, score=2.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF2C8C4338F for ; Thu, 19 Aug 2021 13:34:10 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68BEE610A1 for ; Thu, 19 Aug 2021 13:34:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 68BEE610A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1mGiBK-0004KE-20; Thu, 19 Aug 2021 09:34:06 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mGiBE-0004JS-3n for kernelnewbies@kernelnewbies.org; Thu, 19 Aug 2021 09:34:00 -0400 Received: by mail-oo1-xc30.google.com with SMTP id f33-20020a4a89240000b029027c19426fbeso1822992ooi.8 for ; Thu, 19 Aug 2021 06:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=T1LgKW2IJb/DZYZo/OSh4Dy4lvabvGgUPFigKF7Fs9I=; b=vFlXH5FpmqunGJV+VCkMVO+g61uPRKScDqr23wmEnhXdhKSvrViFmf3I6AfIJ/0UUN Bw4fWKfwajE8lIOg56LIoCwbuCTU5B1TFx4JPpeEko5lqC8c+oyfcF9hQ4m24mVzIc/L hjemd69hvFPDLnXGQxg/s2i43CxZR9IF5xai2pRlTy+3iVg8SUMQ/HiRyKYRZgO0v52c esK1bBB6pXB+LKBhXnCtvgIfJsekrjIbjZzsnO6GM9wH7nyJS83o9TQgy0J2Q9fUU5pc DTeT05IFuyMkibAIcULxaAEiMiM6+BAD5dmVlxlwFTO/OT5EdeGDegISgQpSyVY/ekNA 0w7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=T1LgKW2IJb/DZYZo/OSh4Dy4lvabvGgUPFigKF7Fs9I=; b=Aj3BTcdc7eeaeA1Gq+wjMBRNrMJgLZiPGz1/XaqkunFigoKv0bhzpC2yydTMH0P0f8 MDpRVWFQaTMyl4ztzgOHMurqnUTT9LvRqrb0B+8plF89PYln0sQ1cXqEq9jRq7+MCZR5 5SDUVtRUVGHSlrWI/nsAVsF+DMKQeL2paoWzAJvGar7DO0tH9FhoQ47UtkC7SmVOddGv O8VZyoe3fphA+cxa2Vn6aOoGFt0RkORbxDHs1USgFgFWbG6odOmpHPy8NRd8c7Pc31nK TzX2YGidOGYmLnviOzP4ukN01sy/sBjzBqYkc7/YvK8KI+2vR42M2A4ynWr7tJZ/hroI TKtA== X-Gm-Message-State: AOAM532FAvT+GaQjVHNXQbsqBk5PlaOikPkqEhrr8LvIJnGctsGcNG3x 4Rpi1tlnIEj9n/6FUkSkKMEJ2Yqwbjx/zEcqN66YWJR6 X-Google-Smtp-Source: ABdhPJzfvZfmstCUxuWRMd9dh7wWdavIC223kX4A5mF+cfUZNzgMFdKNmW8ejjnc/HBdWTLBfg8i5Ti3Pf+RuS8rF1A= X-Received: by 2002:a4a:e4ce:: with SMTP id w14mr5049626oov.76.1629380039144; Thu, 19 Aug 2021 06:33:59 -0700 (PDT) MIME-Version: 1.0 References: <32f8b3aa-1bdd-109a-7267-515bb0fdab20@mails.ucas.ac.cn> In-Reply-To: From: Lloyd Date: Thu, 19 Aug 2021 19:03:48 +0530 Message-ID: Subject: Re: kmalloc - Address is not consecutive To: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============3540353190055703485==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============3540353190055703485== Content-Type: multipart/alternative; boundary="0000000000006ff6b905c9e99a23" --0000000000006ff6b905c9e99a23 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks a lot, it worked :) On Thu, Aug 19, 2021 at 7:00 PM ckim wrote: > Hi! this one is easy :) > For printing pointer in kernel space, you should use %px not %p as forma= t > specifier. I heard this is for security reason(?). > Chan Kim > > =EB=82=B4 Galaxy=EC=97=90=EC=84=9C =EB=B3=B4=EB=83=84 > > > -------- =EC=9B=90=EB=B3=B8 =EC=9D=B4=EB=A9=94=EC=9D=BC -------- > =EB=B0=9C=EC=8B=A0: wuzhouhui > =EB=82=A0=EC=A7=9C: 21/8/19 =EC=98=A4=ED=9B=84 9:17 (GMT+09:00) > =EB=B0=9B=EC=9D=80 =EC=82=AC=EB=9E=8C: Lloyd , ke= rnelnewbies@kernelnewbies.org > =EC=A0=9C=EB=AA=A9: 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]=3D{'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 > --0000000000006ff6b905c9e99a23 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks a lot, it worked :)

On Thu, Aug 19, 2021 at 7:00 PM = ckim <ckim@etri.re.kr> wrote:<= br>
Hi! this one is easy :)
For prin= ting pointer in kernel space, you should use %px=C2=A0 not %p as format spe= cifier. I heard this is for security reason(?).
Chan= Kim

=EB=82=B4 Galaxy=EC=97=90=EC=84=9C =EB=B3=B4=EB=83=84<= /div>


-------- =EC=9B= =90=EB=B3=B8 =EC=9D=B4=EB=A9=94=EC=9D=BC --------
=EB=B0=9C=EC=8B= =A0: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
=EB=82=A0=EC=A7= =9C: 21/8/19 =EC=98=A4=ED=9B=84 9:17 (GMT+09:00)
=EB=B0=9B=EC= =9D=80 =EC=82=AC=EB=9E=8C: Lloyd <lloydkl.tech@gmail.com>, kernelnewbies@kernelnewbies= .org
=EC=A0=9C=EB=AA=A9: Re: kmalloc - Address is not consec= utive



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

>= ; Thanks a lot,
> =C2=A0 Lloyd
>
>
> ______________= _________________________________
> Kernelnewbies mailing list
>= ; Kern= elnewbies@kernelnewbies.org
> https://lists.ker= nelnewbies.org/mailman/listinfo/kernelnewbies


______________= _________________________________
Kernelnewbies mailing list
Kernelnewbies= @kernelnewbies.org
https://lists.kernelnewbies.org= /mailman/listinfo/kernelnewbies
______________________________= _________________
Kernelnewbies mailing list
Kernel= newbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailma= n/listinfo/kernelnewbies
--0000000000006ff6b905c9e99a23-- --===============3540353190055703485== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============3540353190055703485==--