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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC6FEC433FE for ; Thu, 3 Nov 2022 21:04:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FA7F6B0073; Thu, 3 Nov 2022 17:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 583926B0074; Thu, 3 Nov 2022 17:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44C5D6B0075; Thu, 3 Nov 2022 17:04:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 34E486B0073 for ; Thu, 3 Nov 2022 17:04:39 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EEA26121315 for ; Thu, 3 Nov 2022 21:04:38 +0000 (UTC) X-FDA: 80093359836.23.1B7FF77 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 7C79640005 for ; Thu, 3 Nov 2022 21:04:38 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8CAF46200B for ; Thu, 3 Nov 2022 21:04:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F3E5C4347C for ; Thu, 3 Nov 2022 21:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667509477; bh=KoiwtwxOFtywoer6DVhuuU206cSyG1Ct3vE1IS6mSso=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=uYjPI3z7hDgTTlt7jAOy1DqEHosYSvhZveN66J6m9u7fnVQfmTP4dD56OZJROqRqR EXc99gAU+tZzqGG97jUc0I0tU8PKvYkmVLYbaZqSnv/wOInTUqWtIVDYj/NZMnM8Wq lSOr6bIgeJ0B9veDA6sgke2ZfZZJP9zuFzHk0eWqE2iRoMaFY3MWaOp19xnRrQoRWv UF2bQt+XPQuMUYXfzhBeIJtbi44nDJVNK43CsUvMms7w1Dh40oTBugsXO90QE+KXTU a4BqCFyfqhzJHkozGpZ20Di9rYFNORijYMBdwj1lOecFN32+Tn2urwed3jjWjEptt9 6kbkuuO97wZxw== Received: by mail-ej1-f53.google.com with SMTP id 13so8648510ejn.3 for ; Thu, 03 Nov 2022 14:04:37 -0700 (PDT) X-Gm-Message-State: ACrzQf1vymIg5nCN+H1FOSZoaD6TmLbIVzZW9sOrta4nTo1ZM2tbyIFm I+FLB9GLzgIk4DtPyURy/N1125noZBXg0y6zfJs= X-Google-Smtp-Source: AMsMyM59wJGWw6eOzYpikm1npeXtKo29IzgzLaFkJDqlnyhINxonsRZIQKUkKCmeqBin6mKBOkntrgYnezAlqMHUdi0= X-Received: by 2002:a17:907:628f:b0:72f:58fc:3815 with SMTP id nd15-20020a170907628f00b0072f58fc3815mr30385410ejc.719.1667509475620; Thu, 03 Nov 2022 14:04:35 -0700 (PDT) MIME-Version: 1.0 References: <20221031222541.1773452-1-song@kernel.org> <20221031222541.1773452-6-song@kernel.org> In-Reply-To: From: Song Liu Date: Thu, 3 Nov 2022 14:04:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v1 RESEND 5/5] x86: use register_text_tail_vm To: "Edgecombe, Rick P" Cc: "linux-mm@kvack.org" , "bpf@vger.kernel.org" , "hch@lst.de" , "mcgrof@kernel.org" , "peterz@infradead.org" , "akpm@linux-foundation.org" , "x86@kernel.org" , "Hansen, Dave" Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667509478; a=rsa-sha256; cv=none; b=BZcoWEiIuPLLNztDlVNuFD4l6gVVZNxk+4NvEdO4BEBZ42xotOYWBtdmJmCtsssXThjItX tSTVaBPcxG7Wm/ldGWqTm+KD4kMqWjSHSsKS2FKY0QBxUsnR8G3uv4IIejZjz+9sX+uvof 2Ej1CTCQhiEFWBwCKYBAao0o0cid2oI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uYjPI3z7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of song@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=song@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667509478; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=R4o0GAALX5W+7sMWhpF6fXkfibK/G9my32T9B+R+QY4=; b=Q1OB4huzKVgaaBgQvowRk4tkSlAM88xYJYEMp0oSQjlKR68I0dY/+H3TSLlf87nkdfWWQW Viv89LDT7CrRPc1k/qThdXe8oDMPJKQVEGPCE8dtNrrUMNiiMuCZmDtzHNe1ySuBs9rRet BTfH2pFCcS+i4zY6x9eLePk1hJSZCu0= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uYjPI3z7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of song@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=song@kernel.org X-Stat-Signature: 1brtu7pktgt3ckneh43rerdz8epjj7q3 X-Rspamd-Queue-Id: 7C79640005 X-HE-Tag: 1667509478-429225 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 2, 2022 at 3:24 PM Edgecombe, Rick P wrote: > > On Mon, 2022-10-31 at 15:25 -0700, Song Liu wrote: > > Allocate 2MB pages up to round_up(_etext, 2MB), and register memory > > [round_up(_etext, 4kb), round_up(_etext, 2MB)] with > > register_text_tail_vm > > so that we can use this part of memory for dynamic kernel text (BPF > > programs, etc.). > > > > Here is an example: > > > > [root@eth50-1 ~]# grep _etext /proc/kallsyms > > ffffffff82202a08 T _etext > > > > [root@eth50-1 ~]# grep bpf_prog_ /proc/kallsyms | tail -n 3 > > ffffffff8220f920 t > > bpf_prog_cc61a5364ac11d93_handle__sched_wakeup [bpf] > > ffffffff8220fa28 t > > bpf_prog_cc61a5364ac11d93_handle__sched_wakeup_new [bpf] > > ffffffff8220fad4 t > > bpf_prog_3bf73fa16f5e3d92_handle__sched_switch [bpf] > > > > [root@eth50-1 ~]# grep 0xffffffff82200000 > > /sys/kernel/debug/page_tables/kernel > > 0xffffffff82200000- > > 0xffffffff82400000 2M ro PSE x pmd > > > > ffffffff82200000-ffffffff82400000 is a 2MB page, serving kernel text, > > and > > bpf programs. > > > > Signed-off-by: Song Liu > > --- > > arch/x86/include/asm/pgtable_64_types.h | 1 + > > arch/x86/mm/init_64.c | 4 +++- > > include/linux/vmalloc.h | 4 ++++ > > 3 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/include/asm/pgtable_64_types.h > > b/arch/x86/include/asm/pgtable_64_types.h > > index 04f36063ad54..c0f9cceb109a 100644 > > --- a/arch/x86/include/asm/pgtable_64_types.h > > +++ b/arch/x86/include/asm/pgtable_64_types.h > > @@ -101,6 +101,7 @@ extern unsigned int ptrs_per_p4d; > > #define PUD_MASK (~(PUD_SIZE - 1)) > > #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) > > #define PGDIR_MASK (~(PGDIR_SIZE - 1)) > > +#define PMD_ALIGN(x) (((unsigned long)(x) + (PMD_SIZE - 1)) & > > PMD_MASK) > > > > /* > > * See Documentation/x86/x86_64/mm.rst for a description of the > > memory map. > > diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c > > index 3f040c6e5d13..5b42fc0c6099 100644 > > --- a/arch/x86/mm/init_64.c > > +++ b/arch/x86/mm/init_64.c > > @@ -1373,7 +1373,7 @@ void mark_rodata_ro(void) > > unsigned long start = PFN_ALIGN(_text); > > unsigned long rodata_start = PFN_ALIGN(__start_rodata); > > unsigned long end = (unsigned long)__end_rodata_hpage_align; > > - unsigned long text_end = PFN_ALIGN(_etext); > > + unsigned long text_end = PMD_ALIGN(_etext); > > unsigned long rodata_end = PFN_ALIGN(__end_rodata); > > unsigned long all_end; > > Check out is_errata93(). Right now it assumes all text is between text- > etext and MODULES_VADDR-MODULES_END. It's a quite old errata, but it > would be nice if we had a is_text_addr() helper or something. To help > keep track of the places where text might pop up. > > Speaking of which, it might be nice to update > Documentation/x86/x86_64/mm.rst with some hints that this area exists. > > > > > @@ -1414,6 +1414,8 @@ void mark_rodata_ro(void) > > (void *)rodata_end, (void *)_sdata); > > > > debug_checkwx(); > > + register_text_tail_vm(PFN_ALIGN((unsigned long)_etext), > > + PMD_ALIGN((unsigned long)_etext)); > > } > > > > int kern_addr_valid(unsigned long addr) > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > > index 9b2042313c12..7365cf9c4e7f 100644 > > --- a/include/linux/vmalloc.h > > +++ b/include/linux/vmalloc.h > > @@ -132,11 +132,15 @@ extern void vm_unmap_aliases(void); > > #ifdef CONFIG_MMU > > extern void __init vmalloc_init(void); > > extern unsigned long vmalloc_nr_pages(void); > > +void register_text_tail_vm(unsigned long start, unsigned long end); > > #else > > static inline void vmalloc_init(void) > > { > > } > > static inline unsigned long vmalloc_nr_pages(void) { return 0; } > > +void register_text_tail_vm(unsigned long start, unsigned long end) > > +{ > > +} > > #endif > > This looks like it should be in the previous patch. Good catch! I will fix it in the next version. Thanks, Song > > > > > extern void *vmalloc(unsigned long size) __alloc_size(1);