Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1151581imm; Wed, 1 Aug 2018 11:02:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe8FXjvIMIVmmsZ5aZ2w7zzIPoHgLd1ewLXt0HLDW+djK2SU1TQ6YdYhBbCB3honVcT4BDr X-Received: by 2002:a17:902:1a2:: with SMTP id b31-v6mr24980962plb.279.1533146556558; Wed, 01 Aug 2018 11:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533146556; cv=none; d=google.com; s=arc-20160816; b=Zlo4yh1mKsohrJDCedx1y5mEFJv1hGaKzHRrFIIokzjg4pKDwNL9LQw1cOpLy/exfg S5+oNwhR9WI6akb2jYD28Om2tn1j05l3yiaUPyZW3gO2F4hmAH+1HIZK66FYjQTW7pl+ LieabaG4IOROh4UCLPunVs4iTZvXWb506Xyk9AGKZZD0FF0eMwbqXO8RFMUhvxNWPyrp aisvLuj5Z/taZCRO/DGOSZF6+iszBRUFGnxxlcyjiOrYzRhr0niFRqZIU7CXFwF11D5P mHaT926Kq+nmtie5arI+Apa8veukz6i+iZ+6V5Np9mIBlmwHgM79rXjINP4JD6RvJsbY Naqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:arc-authentication-results; bh=EZ0FKf3swDItSG17YJb7OxK36wrZzDKkhFW3gIfNUak=; b=g2OgIR6gSWYkn0ark/lcssleF3R+DaWWlMfbGlWeGif75DsJk7ON4VsJeXTScaSl0b TfXeuKgsQl6grKqgTvYJJWTUIxDav5CGrflxyLi2VYFBob9lHjMc3vJ+SR/d6/gKcOUr qkz9A0Hium1R+6O2xpjI35Ctz/dGLbRwSzx5KRlLP5K71yz+N7frb56WzUDgLt95pBlp syoFEGbLhj51mEq9/lX7PAvFAyA3TUz9oy7ej1Ze5WocuvOBJfqlwUBkOW4lCB5dwmln Om1mGztq05N0sqX2v+8sHraobX8RlqBrxSokOvT71L80cjXOO86udSjijyU++Fe9Vepv pDeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9-v6si16104712pfg.27.2018.08.01.11.02.21; Wed, 01 Aug 2018 11:02:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732592AbeHATsZ (ORCPT + 99 others); Wed, 1 Aug 2018 15:48:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:59002 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731689AbeHATsZ (ORCPT ); Wed, 1 Aug 2018 15:48:25 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2018 11:01:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,432,1526367600"; d="scan'208";a="220951779" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga004.jf.intel.com with ESMTP; 01 Aug 2018 11:01:07 -0700 Subject: [PATCH 4/5] x86/mm/init: add helper for freeing kernel image pages To: linux-kernel@vger.kernel.org Cc: Dave Hansen , keescook@google.com, tglx@linutronix.de, mingo@kernel.org, aarcange@redhat.com, jgross@suse.com, jpoimboe@redhat.com, gregkh@linuxfoundation.org, peterz@infradead.org, hughd@google.com, torvalds@linux-foundation.org, bp@alien8.de, luto@kernel.org, ak@linux.intel.com From: Dave Hansen Date: Wed, 01 Aug 2018 11:01:03 -0700 References: <20180801180058.EC46D963@viggo.jf.intel.com> In-Reply-To: <20180801180058.EC46D963@viggo.jf.intel.com> Message-Id: <20180801180103.E42368F9@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen When chunks of the kernel image are freed, free_init_pages() is used directly. Consolidate the three sites that do this. Also update the string to give an incrementally better description of that memory versus what was there before. Signed-off-by: Dave Hansen Cc: Kees Cook Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Andrea Arcangeli Cc: Juergen Gross Cc: Josh Poimboeuf Cc: Greg Kroah-Hartman Cc: Peter Zijlstra Cc: Hugh Dickins Cc: Linus Torvalds Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Andi Kleen --- b/arch/x86/include/asm/processor.h | 1 + b/arch/x86/mm/init.c | 15 ++++++++++++--- b/arch/x86/mm/init_64.c | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff -puN arch/x86/include/asm/processor.h~x86-mm-init-common-kernel-image-free-helper arch/x86/include/asm/processor.h --- a/arch/x86/include/asm/processor.h~x86-mm-init-common-kernel-image-free-helper 2018-07-30 09:53:14.295915691 -0700 +++ b/arch/x86/include/asm/processor.h 2018-07-30 09:53:14.303915690 -0700 @@ -975,6 +975,7 @@ static inline uint32_t hypervisor_cpuid_ extern unsigned long arch_align_stack(unsigned long sp); extern void free_init_pages(char *what, unsigned long begin, unsigned long end); +extern void free_kernel_image_pages(void *begin, void *end); void default_idle(void); #ifdef CONFIG_XEN diff -puN arch/x86/mm/init_64.c~x86-mm-init-common-kernel-image-free-helper arch/x86/mm/init_64.c --- a/arch/x86/mm/init_64.c~x86-mm-init-common-kernel-image-free-helper 2018-07-30 09:53:14.297915691 -0700 +++ b/arch/x86/mm/init_64.c 2018-07-30 09:53:14.304915690 -0700 @@ -1283,8 +1283,8 @@ void mark_rodata_ro(void) set_memory_ro(start, (end-start) >> PAGE_SHIFT); #endif - free_init_pages("unused kernel", text_end, rodata_start); - free_init_pages("unused kernel", rodata_end, _sdata); + free_kernel_image_pages((void *)text_end, (void *)rodata_start); + free_kernel_image_pages((void *)rodata_end, (void *)_sdata); debug_checkwx(); diff -puN arch/x86/mm/init.c~x86-mm-init-common-kernel-image-free-helper arch/x86/mm/init.c --- a/arch/x86/mm/init.c~x86-mm-init-common-kernel-image-free-helper 2018-07-30 09:53:14.298915691 -0700 +++ b/arch/x86/mm/init.c 2018-07-30 09:53:14.304915690 -0700 @@ -771,13 +771,22 @@ void free_init_pages(char *what, unsigne } } +/* + * begin/end can be in the direct map or the "high kernel mapping" + * used for the kernel image only. free_init_pages() will do the + * right thing for either kind of address. + */ +void free_kernel_image_pages(void *begin, void *end) +{ + free_init_pages("unused kernel image", + (unsigned long)begin, (unsigned long)end); +} + void __ref free_initmem(void) { e820__reallocate_tables(); - free_init_pages("unused kernel", - (unsigned long)(&__init_begin), - (unsigned long)(&__init_end)); + free_kernel_image_pages(&__init_begin, &__init_end); } #ifdef CONFIG_BLK_DEV_INITRD _