Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp155619imm; Thu, 2 Aug 2018 16:00:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekzhQmCsRC0b4FYTpI2E3QlJWZyl5MlsBdziuf/SIOzzq23zb+DjOP+4r5f2lLrXoFNdbd X-Received: by 2002:a17:902:6b0b:: with SMTP id o11-v6mr1168523plk.214.1533250847447; Thu, 02 Aug 2018 16:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533250847; cv=none; d=google.com; s=arc-20160816; b=tjQH3ZWOgz6hNKLCCcL7VBzCmQmGdScCpTAiW1W/yCACe0XkhQrb2rlQBNHYc7Ywj1 vUk9mWTspNic6ykIaSMop9rmIAv0LjCrEgYBEqD0Asxwi+RWo7kg35Z8p/ZlL/8cy8za VCKMvB8sSW0fS+ioWxJDlELF+pupOlZylhGuW7Wo/xZR/v7sgXDInmfinvghC1Az7DA4 w+X6bAKrWb9Vtdu37HJ04h9rUK4JGnqmrjRAj+oGdVCWE8bRjRjwb4IoOcot8UAKdoyA W3UiRcSimL+uUJQ1vJPvA3ECyWQFqzWtCrT/LgBnLddudR4wVT9hkO+o5KK0Jxpn2ou+ rgCA== 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=ahi8AYmBMj2ycbutC4Mh4NyBi5+qyewr5eUXzY6ucoc=; b=TH7xHLrkNS7vd1qpINZtODi4ae7dTO5axgvxsRyjiwKb9CgUPA/yrHsvPR+xr+46b3 RiSAtp8xGKwX+LB1bFmXCGVEG5stsKWtnVEA2M1GCrevzjO8aSClQC2I6+BrVZSyyWE2 /HRHv0/FKEoWnwJjc9C3f+2zRnN4niD6UyZbGWLQMQRbkRfuUouTsKmCktQalEpBDuHf T1rf21G5VGkGI+6LYBObTLCfExFepyZHkdXy2vscH6thqJmrrVzihcn+APXZBzymAj8U ZunTsQuj6eXcfKX5MKnez73Y/KabZnHknfpSBoFGftxyVkn3ZBLO/GhXK2nX6hasXlvl Zi+w== 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 y23-v6si2466844pli.389.2018.08.02.16.00.32; Thu, 02 Aug 2018 16:00:47 -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 S1732266AbeHCAv5 (ORCPT + 99 others); Thu, 2 Aug 2018 20:51:57 -0400 Received: from mga05.intel.com ([192.55.52.43]:51188 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbeHCAv5 (ORCPT ); Thu, 2 Aug 2018 20:51:57 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Aug 2018 15:58:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,437,1526367600"; d="scan'208";a="251278100" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga006.fm.intel.com with ESMTP; 02 Aug 2018 15:58:38 -0700 Subject: [PATCH 4/7] 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: Thu, 02 Aug 2018 15:58:29 -0700 References: <20180802225823.4711C55B@viggo.jf.intel.com> In-Reply-To: <20180802225823.4711C55B@viggo.jf.intel.com> Message-Id: <20180802225829.FE0E32EA@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-08-02 14:14:48.891483276 -0700 +++ b/arch/x86/include/asm/processor.h 2018-08-02 14:14:48.901483276 -0700 @@ -966,6 +966,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-08-02 14:14:48.895483276 -0700 +++ b/arch/x86/mm/init_64.c 2018-08-02 14:14:48.902483276 -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-08-02 14:14:48.896483276 -0700 +++ b/arch/x86/mm/init.c 2018-08-02 14:14:48.902483276 -0700 @@ -773,13 +773,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 _