Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp236977ybp; Thu, 10 Oct 2019 17:13:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvEc/Kev+dCC6u0mhc08zdNKlnmLxlCtidufF/ZrBPaAdooyJo+PnytidirWrld0NXAVHk X-Received: by 2002:a05:6402:7ca:: with SMTP id u10mr10829285edy.20.1570752828780; Thu, 10 Oct 2019 17:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570752828; cv=none; d=google.com; s=arc-20160816; b=i8RkVnAnmXoc7o4gpxSDOQ9Z2J1w7EVUASttbvzL8XBilzY2bV7V2+K17+xzVBI0BM 7g11z5Xok8kP4cR08rkpB3pwsnBn6l/IYFzIYon4rFDGyatR+Nd9sBItLOKozqWFfIli 9y2FSLO0YOA1nWImlePssnz3leLVN8nn8omrH5okkk0uQThS0drx0hvsnB9Sheh6aH5I CWzLT1w2TJgmSvemVAYp6CYT/7tIQK5fGvECgjcw6w3D7+jv2ske86yguEZZUJL008B1 B1wzPP+kexDYIQtLTlaXp1AWMZ8zj5Pkvq5mQKWx0zPAvayPtiXl2fDe1EhYBQZsc1IV MSsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CyoXOdP2RSQBzcYa2ar7sJXCOKRhNFJ5bhxtCWldzm0=; b=chMOPM6A77L46746x1HjmqKbzRq/Qz660+Ty0uW7gBA77ufslkEu5w/bg5fxVpIgYT J1UcNwlOi/KXP9ABBW9MVnLZDT+CsvCqk/9WNRyBod9caGkzp2n6NHsjbduj404AjYlw Y1RcEzUuKnPj9ltR1groH1Co+OVpC1aobjP4GUuDSg7deWaWhPoronL1Iy82r4TADmVe Mg3eIpRtaze5lV68v803orpaUqd0LELw3k1bHRgXUPbQt8X9Zgfmx/ht9F1IXRRCQp4p mUsDxPk73rBU5ZzrfI+QER23BWi66FRuh1c0V3bqK5encGWI91VMZSQF9inBQxn/aJxN PxUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lj7QNKSF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k63si4813660edc.347.2019.10.10.17.13.25; Thu, 10 Oct 2019 17:13:48 -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; dkim=pass header.i=@chromium.org header.s=google header.b=Lj7QNKSF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbfJKANE (ORCPT + 99 others); Thu, 10 Oct 2019 20:13:04 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35527 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbfJKANC (ORCPT ); Thu, 10 Oct 2019 20:13:02 -0400 Received: by mail-pg1-f194.google.com with SMTP id p30so4707797pgl.2 for ; Thu, 10 Oct 2019 17:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CyoXOdP2RSQBzcYa2ar7sJXCOKRhNFJ5bhxtCWldzm0=; b=Lj7QNKSFAWUpBfpzOt7+g6iG1nZwQWiy2Yx2COX4rHzLDwe7zAeBtuvEmbHCBjMdVS f7OItuAMoBx4ANIxisnsIuIzLX/n/2wSchdTwd5gBy79nJpGqvgOWz8QIjj/yjSDeyUu Nk/yU3k7rraRoC3ReBbUSn8UR29/tNR/sk7J8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CyoXOdP2RSQBzcYa2ar7sJXCOKRhNFJ5bhxtCWldzm0=; b=ZoPCYawjfugPQ2NXcK+Ni8m4WpMFFvexZ5+VlelVR2Zrs+uh1DZ2fgVT5kIrpFCyik aeDSmVZzMGsXXjdBwqXhYdVVWqu1QtJ3BmhnxYpcIOxFKWm2Zyc4Ld9jOzCz5z8cKAEY gLTH63Q0rqA7WRj8/IFUzM7rMXSR2cCkIWVWM1pgWhq4E8IkcqitNmqFhC5X2z9TFYMD xDKz9Hf/ef9SO96n9UkV+zRlEyvZe2c5zUihzotJM3++zrB8PrixkXasDbUuGrTFEbRb CS6ZqPCaDFWknPvQY4S9zMcV6W4DHuxwCzn8CeFfmmjRUVzsDONypCsjDzDBYa93bgUy f7Vg== X-Gm-Message-State: APjAAAWQNQkgYdRTqL+iBbjZzeqESiXkoAEhz7PLRvE0mmGs/aBQMtUd C+1etEIMch2Ep9cZKHhvpiq+TkNVRb8= X-Received: by 2002:aa7:9907:: with SMTP id z7mr13951279pff.192.1570752781298; Thu, 10 Oct 2019 17:13:01 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t12sm5458788pjq.18.2019.10.10.17.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 17:12:56 -0700 (PDT) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , Rick Edgecombe , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Michael Ellerman , Heiko Carstens , Will Deacon , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-alpha@vger.kernel.org, linux-ia64@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michal Simek , linux-parisc@vger.kernel.org, linux-xtensa@linux-xtensa.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 27/29] x86/mm: Report which part of kernel image is freed Date: Thu, 10 Oct 2019 17:06:07 -0700 Message-Id: <20191011000609.29728-28-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191011000609.29728-1-keescook@chromium.org> References: <20191011000609.29728-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memory freeing report wasn't very useful for figuring out which parts of the kernel image were being freed. Add the details for clearer reporting in dmesg. Before: [ 2.150450] Freeing unused kernel image memory: 1348K [ 2.154574] Write protecting the kernel read-only data: 20480k [ 2.157641] Freeing unused kernel image memory: 2040K [ 2.158827] Freeing unused kernel image memory: 172K After: [ 2.329678] Freeing unused kernel image (initmem) memory: 1348K [ 2.331953] Write protecting the kernel read-only data: 20480k [ 2.335361] Freeing unused kernel image (text/rodata gap) memory: 2040K [ 2.336927] Freeing unused kernel image (rodata/data gap) memory: 172K Signed-off-by: Kees Cook --- arch/x86/include/asm/processor.h | 2 +- arch/x86/mm/init.c | 8 ++++---- arch/x86/mm/init_64.c | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 6e0a3b43d027..790f250d39a8 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -958,7 +958,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) extern unsigned long arch_align_stack(unsigned long sp); void free_init_pages(const char *what, unsigned long begin, unsigned long end); -extern void free_kernel_image_pages(void *begin, void *end); +extern void free_kernel_image_pages(const char *what, void *begin, void *end); void default_idle(void); #ifdef CONFIG_XEN diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index fd10d91a6115..e7bb483557c9 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -829,14 +829,13 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end) * 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) +void free_kernel_image_pages(const char *what, void *begin, void *end) { unsigned long begin_ul = (unsigned long)begin; unsigned long end_ul = (unsigned long)end; unsigned long len_pages = (end_ul - begin_ul) >> PAGE_SHIFT; - - free_init_pages("unused kernel image", begin_ul, end_ul); + free_init_pages(what, begin_ul, end_ul); /* * PTI maps some of the kernel into userspace. For performance, @@ -865,7 +864,8 @@ void __ref free_initmem(void) mem_encrypt_free_decrypted_mem(); - free_kernel_image_pages(&__init_begin, &__init_end); + free_kernel_image_pages("unused kernel image (initmem)", + &__init_begin, &__init_end); } #ifdef CONFIG_BLK_DEV_INITRD diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index e67ddca8b7a8..dcb9bc961b39 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1334,8 +1334,10 @@ void mark_rodata_ro(void) set_memory_ro(start, (end-start) >> PAGE_SHIFT); #endif - free_kernel_image_pages((void *)text_end, (void *)rodata_start); - free_kernel_image_pages((void *)rodata_end, (void *)_sdata); + free_kernel_image_pages("unused kernel image (text/rodata gap)", + (void *)text_end, (void *)rodata_start); + free_kernel_image_pages("unused kernel image (rodata/data gap)", + (void *)rodata_end, (void *)_sdata); debug_checkwx(); } -- 2.17.1