From patchwork Wed Aug 15 20:30:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10566801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26D4B14E1 for ; Wed, 15 Aug 2018 20:34:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBAFE2ACA9 for ; Wed, 15 Aug 2018 20:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFCD32B006; Wed, 15 Aug 2018 20:34:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D8AB2ACA9 for ; Wed, 15 Aug 2018 20:34:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5357A6B026E; Wed, 15 Aug 2018 16:34:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4EEBA6B0270; Wed, 15 Aug 2018 16:34:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FC8F6B0271; Wed, 15 Aug 2018 16:34:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id E8A456B026E for ; Wed, 15 Aug 2018 16:34:21 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id d10-v6so1260289pll.22 for ; Wed, 15 Aug 2018 13:34:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=gTrnlqy16kqpxjxGPq3uKDcEk2l/OvHsgL8/LW0Lw2w=; b=RDHSR4YeicClIp+nNFiT+Ubc8TqtUNAWtISt4ytQSSwYuyvI15S9OoqqtpDwlMCkFb MO0QcK8jbk2ssqeSg2X6263B2Y/uLgVTRwSnvn48b2t/vDwyf+PPD9yHOH9pCJPciULW jgiFALu5WH2sdbZE1aWT7IsPNXOS2JUtL6FmMrF8eV9wVqCwB4Tbwz04ElpgsP4L4MrK mc1mHjcustSG79x7ZOf4YXVi6G+bTqarbX3xjopA5l6tLCAL/niQz+q8lAOZUD4kpe97 1cHhY7fJfGaB9sWUmAkSCFpNqCOyH/qbxpkgFooCRZQqCjGtT2soG+8VwK9A2CUzBlEe qizQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlEzR2IjYKlWOP1vhlOMAGfTvYupSHwgDTwGYgyUYQani6LaOplk 89s2MXzByVeI2LSxp2f7IBgR87/CUd9lIK0/cXwrXGlJUQHY6zgb+sJROm9TMElxDLOrOUCy1CW gEBCdd2jnS4hZuTb9nDPb3QszQlFKbxslBrKeu/Nak7ubc+Eneb8KPtdFt4FrGt7rHQ== X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr25325737pli.191.1534365261613; Wed, 15 Aug 2018 13:34:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxhTiVcvrmFK8SA5uwFI90X3RspkeT+tVL6kjq0bJYG612G0mcJ6jerpaZGfFClq1jCuoJy X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr25325687pli.191.1534365260634; Wed, 15 Aug 2018 13:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534365260; cv=none; d=google.com; s=arc-20160816; b=XmBmmnF6Zt6MulSwKiySw9fFlT4b7xfK/wNZZD0A/0IZPe95FcLZjrQ4QsXTyoU8A/ U/wXetRZAYyco0Ysdr623DboI61T/NjxZlmH6qwKFtiRVg7S57LGDoFwZNAx79QiXCxJ KE11cLINJ6NBsuLdsFNa1g4/DtADzNh/fVeGZG7HBEG5GZXzC2n5X+ZNDdkvw0ROnqcS R/oRQAvW9LYPLkSWOZ8GYptRXavFAtiUouB7VkABIxCWXS5tMIe7lmEGLnm6pFk7OH0E rrPTjNtRgbGXpsKOp1rZJ2mQBq5cBbdEGekcvOjiCB+iC2EmW0h7zKRiPGwpUYtpECMq MdJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=gTrnlqy16kqpxjxGPq3uKDcEk2l/OvHsgL8/LW0Lw2w=; b=STrsAV4gDLRSFjCOGTjE7d3XdRaIVc8UW/xN7Qc0k1bokF+hqNSjOAQeruks5HIAV3 2w/ZgGjSmWWtlj8J4WdJiH/kyNDq60Ds9BTsOcy95aGNFrAMqfIkIHpjKu8UYMFDqcoW TdZBObrFUMKMUP+XkE+HW5oWn/l1TzBiSQkRe8lSb7T6kYwRay94W4x1CYgHisgCJVRS NBYhrwELZKlppxRqGLJzVCLgybv+HuLAdVfYbtaNuF6A1yQOb2IIRfTCqbWOCETKuclC 5ab6QwnFmBt+mkVXLFF6y2Z/ha301RtvJJH2wFGmMW7LfWzhkmtCSusHBJZ+YO5CZFXu j1/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id n3-v6si18917408pld.146.2018.08.15.13.34.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Aug 2018 13:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Aug 2018 13:34:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,244,1531810800"; d="scan'208";a="224930399" Received: from rpedgeco-hp-z240-tower-workstation.jf.intel.com (HELO rpedgeco-DESK5.jf.intel.com) ([10.54.75.168]) by orsmga004.jf.intel.com with ESMTP; 15 Aug 2018 13:34:18 -0700 From: Rick Edgecombe To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com, daniel@iogearbox.net, jannh@google.com, keescook@chromium.org Cc: kristen@linux.intel.com, dave.hansen@intel.com, arjan@linux.intel.com, Rick Edgecombe Subject: [PATCH v3 3/3] vmalloc: Add debugfs modfraginfo Date: Wed, 15 Aug 2018 13:30:19 -0700 Message-Id: <1534365020-18943-4-git-send-email-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534365020-18943-1-git-send-email-rick.p.edgecombe@intel.com> References: <1534365020-18943-1-git-send-email-rick.p.edgecombe@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP Add debugfs file "modfraginfo" for providing info on module space fragmentation. This can be used for determining if loadable module randomization is causing any problems for extreme module loading situations, like huge numbers of modules or extremely large modules. Sample output when KASLR is enabled and X86_64 is configured: Largest free space: 897912 kB Total free space: 1025424 kB Allocations in backup area: 0 Sample output when just X86_64: Largest free space: 897912 kB Total free space: 1025424 kB Signed-off-by: Rick Edgecombe --- mm/vmalloc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fb85ec9..cb55138 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include +#include #include #include @@ -2925,7 +2927,92 @@ static int __init proc_vmalloc_init(void) proc_create_seq("vmallocinfo", 0400, NULL, &vmalloc_op); return 0; } -module_init(proc_vmalloc_init); +#else +static int __init proc_vmalloc_init(void) +{ + return 0; +} +#endif + +#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_64) +static int modulefraginfo_debug_show(struct seq_file *m, void *v) +{ + unsigned long last_end = MODULES_VADDR; + unsigned long total_free = 0; + unsigned long largest_free = 0; + unsigned long backup_cnt = 0; + unsigned long gap; + struct vmap_area *prev, *cur = NULL; + + spin_lock(&vmap_area_lock); + + if (!pvm_find_next_prev(MODULES_VADDR, &cur, &prev) || !cur) + goto done; + + for (; cur->va_end <= MODULES_END; cur = list_next_entry(cur, list)) { + /* Don't count areas that are marked to be lazily freed */ + if ((cur->flags & VM_LAZY_FREE)) + continue; + + if (cur->va_start >= MODULES_VADDR + MODULES_RAND_LEN) + backup_cnt++; + gap = cur->va_start - last_end; + if (gap > largest_free) + largest_free = gap; + total_free += gap; + last_end = cur->va_end; + + if (list_is_last(&cur->list, &vmap_area_list)) + break; + } + +done: + gap = (MODULES_END - last_end); + if (gap > largest_free) + largest_free = gap; + total_free += gap; + + spin_unlock(&vmap_area_lock); + seq_printf(m, "\tLargest free space:\t%lu kB\n", largest_free / 1024); + seq_printf(m, "\t Total free space:\t%lu kB\n", total_free / 1024); + + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled()) + seq_printf(m, "Allocations in backup area:\t%lu\n", backup_cnt); + + return 0; +} + +static int proc_module_frag_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, modulefraginfo_debug_show, NULL); +} + +static const struct file_operations debug_module_frag_operations = { + .open = proc_module_frag_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void __init debug_modfrag_init(void) +{ + debugfs_create_file("modfraginfo", 0400, NULL, NULL, + &debug_module_frag_operations); +} +#else /* defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_64) */ +static void __init debug_modfrag_init(void) +{ +} #endif +#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PROC_FS) +static int __init info_vmalloc_init(void) +{ + proc_vmalloc_init(); + debug_modfrag_init(); + return 0; +} + +module_init(info_vmalloc_init); +#endif