All of lore.kernel.org
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] kernel: add kcov code coverage
Date: Mon, 18 Jan 2016 14:13:52 +0000	[thread overview]
Message-ID: <20160118141352.GM21067@leverpostej> (raw)
In-Reply-To: <CACT4Y+YvL_L9a2dBfoXQ0AKpKmnypfObtt7k97j_i2Qiu=wnQg@mail.gmail.com>

On Fri, Jan 15, 2016 at 03:07:59PM +0100, Dmitry Vyukov wrote:
> On Fri, Jan 15, 2016 at 2:05 PM, Andrey Ryabinin <ryabinin.a.a@gmail.com> wrote:
> > 2016-01-14 17:30 GMT+03:00 Dmitry Vyukov <dvyukov@google.com>:
> >> On Thu, Jan 14, 2016 at 11:50 AM, Andrey Ryabinin
> >> <ryabinin.a.a@gmail.com> wrote:
> >>> 2016-01-13 15:48 GMT+03:00 Dmitry Vyukov <dvyukov@google.com>:
> >>>
> >>>> +       /* Read number of PCs collected. */
> >>>> +       n = __atomic_load_n(&cover[0], __ATOMIC_RELAXED);
> >>>> +       /* PCs are shorten to uint32_t, so we need to restore the upper part. */
> >>>> +       for (i = 0; i < n; i++)
> >>>> +               printf("0xffffffff%0lx\n", (unsigned long)cover[i + 1]);
> >>
> >> Thanks for the review!
> >> Mailed v3 with fixes.
> >> Comments inline.
> >>
> >>> This works only for x86-64.
> >>> Probably there is no simple way to make this arch-independent with
> >>> 32-bit values.
> >>
> >> We probably could add an ioctl that returns base of the stripped PCs.
> >
> > You forgot about modules. With stripped PCs you'll start mixing
> > kernel's and module's PC (if distance between module and kernel > 4G).
> 
> It's just that on x86 text and modules are within 4GB.
> 
> I've checked that on arm64 it also seems to be the case:
> 
>  48  * The module space lives between the addresses given by TASK_SIZE
>  49  * and PAGE_OFFSET - it must be within 128MB of the kernel text.
>  50  */
>  54 #define MODULES_END             (PAGE_OFFSET)
>  55 #define MODULES_VADDR           (MODULES_END - SZ_64M)

This won't necessarily remain true. With kASLR [1,2] the modules and
kernel might be located anywhere in the vmalloc area, independently.
Using PLTs removes the +/-128MB restriction, so they may be placed
anywhere in the vmalloc area.

On my defconfig kernel (4KiB, 39-bit VA) today, that area is ~246GiB wide:

[    0.000000] Virtual kernel memory layout:
[    0.000000]     vmalloc : 0xffffff8000000000 - 0xffffffbdbfff0000   (   246 GB)
[    0.000000]     vmemmap : 0xffffffbdc0000000 - 0xffffffbfc0000000   (     8 GB maximum)
[    0.000000]               0xffffffbdc2000000 - 0xffffffbde8000000   (   608 MB actual)
[    0.000000]     fixed   : 0xffffffbffa7fd000 - 0xffffffbffac00000   (  4108 KB)
[    0.000000]     PCI I/O : 0xffffffbffae00000 - 0xffffffbffbe00000   (    16 MB)
[    0.000000]     modules : 0xffffffbffc000000 - 0xffffffc000000000   (    64 MB)
[    0.000000]     memory  : 0xffffffc000000000 - 0xffffffc980000000   ( 38912 MB)
[    0.000000]       .init : 0xffffffc000a00000 - 0xffffffc000a9c000   (   624 KB)
[    0.000000]       .text : 0xffffffc000080000 - 0xffffffc000a00000   (  9728 KB)
[    0.000000]       .data : 0xffffffc000a9c000 - 0xffffffc000b17a00   (   495 KB)

Kernels can be built with a 48-bit VA (and potentially larger in future
with ARMv8.2-A or later [3]). The vmalloc area (and hence the maximum
distances between modules and kernel) will increase grow with the VA
range.

Thanks,
Mark.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/398527.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/398534.html
[3] https://community.arm.com/groups/processors/blog/2016/01/05/armv8-a-architecture-evolution

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: syzkaller <syzkaller@googlegroups.com>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Tavis Ormandy <taviso@google.com>,
	Will Deacon <will.deacon@arm.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Quentin Casasnovas <quentin.casasnovas@oracle.com>,
	Kostya Serebryany <kcc@google.com>,
	Eric Dumazet <edumazet@google.com>,
	Alexander Potapenko <glider@google.com>,
	Kees Cook <keescook@google.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Sasha Levin <sasha.levin@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Drysdale <drysdale@google.com>,
	linux-arm-kernel@lists.infradead.org, ard.biesheuvel@linaro.org
Subject: Re: [PATCH v2] kernel: add kcov code coverage
Date: Mon, 18 Jan 2016 14:13:52 +0000	[thread overview]
Message-ID: <20160118141352.GM21067@leverpostej> (raw)
In-Reply-To: <CACT4Y+YvL_L9a2dBfoXQ0AKpKmnypfObtt7k97j_i2Qiu=wnQg@mail.gmail.com>

On Fri, Jan 15, 2016 at 03:07:59PM +0100, Dmitry Vyukov wrote:
> On Fri, Jan 15, 2016 at 2:05 PM, Andrey Ryabinin <ryabinin.a.a@gmail.com> wrote:
> > 2016-01-14 17:30 GMT+03:00 Dmitry Vyukov <dvyukov@google.com>:
> >> On Thu, Jan 14, 2016 at 11:50 AM, Andrey Ryabinin
> >> <ryabinin.a.a@gmail.com> wrote:
> >>> 2016-01-13 15:48 GMT+03:00 Dmitry Vyukov <dvyukov@google.com>:
> >>>
> >>>> +       /* Read number of PCs collected. */
> >>>> +       n = __atomic_load_n(&cover[0], __ATOMIC_RELAXED);
> >>>> +       /* PCs are shorten to uint32_t, so we need to restore the upper part. */
> >>>> +       for (i = 0; i < n; i++)
> >>>> +               printf("0xffffffff%0lx\n", (unsigned long)cover[i + 1]);
> >>
> >> Thanks for the review!
> >> Mailed v3 with fixes.
> >> Comments inline.
> >>
> >>> This works only for x86-64.
> >>> Probably there is no simple way to make this arch-independent with
> >>> 32-bit values.
> >>
> >> We probably could add an ioctl that returns base of the stripped PCs.
> >
> > You forgot about modules. With stripped PCs you'll start mixing
> > kernel's and module's PC (if distance between module and kernel > 4G).
> 
> It's just that on x86 text and modules are within 4GB.
> 
> I've checked that on arm64 it also seems to be the case:
> 
>  48  * The module space lives between the addresses given by TASK_SIZE
>  49  * and PAGE_OFFSET - it must be within 128MB of the kernel text.
>  50  */
>  54 #define MODULES_END             (PAGE_OFFSET)
>  55 #define MODULES_VADDR           (MODULES_END - SZ_64M)

This won't necessarily remain true. With kASLR [1,2] the modules and
kernel might be located anywhere in the vmalloc area, independently.
Using PLTs removes the +/-128MB restriction, so they may be placed
anywhere in the vmalloc area.

On my defconfig kernel (4KiB, 39-bit VA) today, that area is ~246GiB wide:

[    0.000000] Virtual kernel memory layout:
[    0.000000]     vmalloc : 0xffffff8000000000 - 0xffffffbdbfff0000   (   246 GB)
[    0.000000]     vmemmap : 0xffffffbdc0000000 - 0xffffffbfc0000000   (     8 GB maximum)
[    0.000000]               0xffffffbdc2000000 - 0xffffffbde8000000   (   608 MB actual)
[    0.000000]     fixed   : 0xffffffbffa7fd000 - 0xffffffbffac00000   (  4108 KB)
[    0.000000]     PCI I/O : 0xffffffbffae00000 - 0xffffffbffbe00000   (    16 MB)
[    0.000000]     modules : 0xffffffbffc000000 - 0xffffffc000000000   (    64 MB)
[    0.000000]     memory  : 0xffffffc000000000 - 0xffffffc980000000   ( 38912 MB)
[    0.000000]       .init : 0xffffffc000a00000 - 0xffffffc000a9c000   (   624 KB)
[    0.000000]       .text : 0xffffffc000080000 - 0xffffffc000a00000   (  9728 KB)
[    0.000000]       .data : 0xffffffc000a9c000 - 0xffffffc000b17a00   (   495 KB)

Kernels can be built with a 48-bit VA (and potentially larger in future
with ARMv8.2-A or later [3]). The vmalloc area (and hence the maximum
distances between modules and kernel) will increase grow with the VA
range.

Thanks,
Mark.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/398527.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/398534.html
[3] https://community.arm.com/groups/processors/blog/2016/01/05/armv8-a-architecture-evolution

  parent reply	other threads:[~2016-01-18 14:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 12:48 [PATCH v2] kernel: add kcov code coverage Dmitry Vyukov
2016-01-13 22:31 ` kbuild test robot
2016-01-14  9:03 ` Kirill A. Shutemov
2016-01-14  9:10   ` Dmitry Vyukov
2016-01-14  9:23     ` Kirill A. Shutemov
2016-01-14 12:21       ` Dmitry Vyukov
2016-01-14 12:35         ` Kirill A. Shutemov
2016-01-14 12:49         ` Kirill A. Shutemov
2016-01-14 14:24           ` Dmitry Vyukov
2016-01-14 10:50 ` Andrey Ryabinin
2016-01-14 14:30   ` Dmitry Vyukov
2016-01-15 13:05     ` Andrey Ryabinin
2016-01-15 13:05       ` Andrey Ryabinin
2016-01-15 13:42       ` Will Deacon
2016-01-15 13:42         ` Will Deacon
2016-01-15 14:07       ` Dmitry Vyukov
2016-01-15 14:07         ` Dmitry Vyukov
2016-01-18 13:34         ` Andrey Ryabinin
2016-01-18 13:34           ` Andrey Ryabinin
2016-01-18 19:31           ` Dmitry Vyukov
2016-01-18 19:31             ` Dmitry Vyukov
2016-01-18 14:13         ` Mark Rutland [this message]
2016-01-18 14:13           ` Mark Rutland
2016-01-18 19:44           ` Dmitry Vyukov
2016-01-18 19:44             ` Dmitry Vyukov
2016-01-18 20:09             ` Dmitry Vyukov
2016-01-18 20:09               ` Dmitry Vyukov
2016-01-22 11:55               ` Mark Rutland
2016-01-22 11:55                 ` Mark Rutland
2016-01-22 12:15                 ` Dmitry Vyukov
2016-01-22 12:15                   ` Dmitry Vyukov
2016-01-22 12:52                   ` Mark Rutland
2016-01-22 12:52                     ` Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160118141352.GM21067@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.