Skip to content

Commit bc47ee4

Browse files
committed
tracing/user_events: Use alloc_pages instead of kzalloc() for register pages
kzalloc virtual addresses do not work with SetPageReserved, use the actual page virtual addresses instead via alloc_pages. The issue is reported when booting with user_events and DEBUG_VM_PGFLAGS=y. Also make the number of events based on the ORDER. Link: https://lore.kernel.org/all/CADYN=9+xY5Vku3Ws5E9S60SM5dCFfeGeRBkmDFbcxX0ZMoFing@mail.gmail.com/ Link: https://lore.kernel.org/all/20220311223028.1865-1-beaub@linux.microsoft.com/ Cc: Beau Belgrave <beaub@linux.microsoft.com> Reported-by: Anders Roxell <anders.roxell@linaro.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 380af29 commit bc47ee4

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

kernel/trace/trace_events_user.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030

3131
/*
3232
* Limits how many trace_event calls user processes can create:
33-
* Must be multiple of PAGE_SIZE.
33+
* Must be a power of two of PAGE_SIZE.
3434
*/
35-
#define MAX_PAGES 1
35+
#define MAX_PAGE_ORDER 0
36+
#define MAX_PAGES (1 << MAX_PAGE_ORDER)
3637
#define MAX_EVENTS (MAX_PAGES * PAGE_SIZE)
3738

3839
/* Limit how long of an event name plus args within the subsystem. */
@@ -1622,16 +1623,17 @@ static void set_page_reservations(bool set)
16221623

16231624
static int __init trace_events_user_init(void)
16241625
{
1626+
struct page *pages;
16251627
int ret;
16261628

16271629
/* Zero all bits beside 0 (which is reserved for failures) */
16281630
bitmap_zero(page_bitmap, MAX_EVENTS);
16291631
set_bit(0, page_bitmap);
16301632

1631-
register_page_data = kzalloc(MAX_EVENTS, GFP_KERNEL);
1632-
1633-
if (!register_page_data)
1633+
pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, MAX_PAGE_ORDER);
1634+
if (!pages)
16341635
return -ENOMEM;
1636+
register_page_data = page_address(pages);
16351637

16361638
set_page_reservations(true);
16371639

@@ -1640,7 +1642,7 @@ static int __init trace_events_user_init(void)
16401642
if (ret) {
16411643
pr_warn("user_events could not register with tracefs\n");
16421644
set_page_reservations(false);
1643-
kfree(register_page_data);
1645+
__free_pages(pages, MAX_PAGE_ORDER);
16441646
return ret;
16451647
}
16461648

0 commit comments

Comments
 (0)