Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp870863ybl; Fri, 10 Jan 2020 08:06:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxjHXGwii3FSEWyYVipgEBxzVg/veM2DTCGt5H4fJXLtJU8/Yjgf5HiwD9kSeus9/AYZbuL X-Received: by 2002:a9d:7b50:: with SMTP id f16mr3280393oto.18.1578672382603; Fri, 10 Jan 2020 08:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578672382; cv=none; d=google.com; s=arc-20160816; b=j6q7b6kZMZMSPw0V7P1cXuw4HjxjIZs5MnBXAUKokmqpleqiXYNwHobCS0NUK/Mh3B /2vbwwCiv2k7AZPLFMIzlY6gmypydMlkl/+OGuHZdlDZGUKDzGCmP9jqSiECDKAmx4R8 GBZz4rJUuTtAgSi3AjvoOcTG2XtPh8PqfgOnv7q8hRjaHrxH/KmUK5na6OVQOJFeEgB1 OhJ977yNyhFy3C9ZvET27ceCbxtAPTCjUkrgGvVv4fmsabvThfpvrWgU98lUP//KCvGw vhNUlZXKDdo1LxIQjO0uNOfJ6ujv2UCkMNTCwfDDz9yz3pZZLPZfwxg77MHv4krliyqk OnIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FWuLqSqGTEvRjwmdPPmnEdgCbeu+gwREVhW+5U/Ee04=; b=feJiT6JlZFNKg4nre50pJ+48dAMSLHNnHWi5mdUzGzuwzAJKGHhpAAW5AhDWHnSSEA Iq0tFWp+3ko0R5n381ftoqqsRF12oXdVZz4UtcrWrVBD/wm6kkrwYkt4/fUpJ/BMSDxg pb02C8ouTl/pnXNi+HQpMsBtQ16X8DXNDKrXvdbI4L1h31SmNB475HFt0sXbGZDY2/88 f3Zjtx2f85xL59wRdAU/q8E7D6W4u9yOpPXITPvMHfydENWxwH2bCuILRqoLYrt/eHit 1gRwIimORkbAF73bvkuxz4n+LjhscV5R1+iPfsdOPbaR+pTMzelDW50voikHTAeNEPQe 7Tuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GWmjgrIH; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6si1512587otn.216.2020.01.10.08.06.02; Fri, 10 Jan 2020 08:06:22 -0800 (PST) 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=@kernel.org header.s=default header.b=GWmjgrIH; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728667AbgAJQE1 (ORCPT + 99 others); Fri, 10 Jan 2020 11:04:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:52726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728474AbgAJQE0 (ORCPT ); Fri, 10 Jan 2020 11:04:26 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F39442082E; Fri, 10 Jan 2020 16:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578672266; bh=LrcWIbBDbw5kMRKdqQoq+o3xV5djx72cOD1i3uPdkrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GWmjgrIHS6HXVvtIUALkLWvFebG3jpSzvC0ERgImy49vJDh4d4Q2f6ungVVBaqZAE dPrcx0+AJajPXTOq6yM1sl3gIBNHpo26q+Wenirm/vPoSjgx7seHCurYl9nl/e3y9z wwL8BxeCtFMuCqejlds/kXxmpMgQIrWjUqyl7dSM= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Frank Rowand , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 05/22] proc: bootconfig: Add /proc/bootconfig to show boot config list Date: Sat, 11 Jan 2020 01:04:19 +0900 Message-Id: <157867225967.17873.12155805787236073787.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157867220019.17873.13377985653744804396.stgit@devnote2> References: <157867220019.17873.13377985653744804396.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add /proc/bootconfig which shows the list of key-value pairs in boot config. Since after boot, all boot configs and tree are removed, this interface just keep a copy of key-value pairs in text. Signed-off-by: Masami Hiramatsu --- Changes in v4: - Remove ; in the end of lines. - Rename /proc/supp_cmdline to /proc/bootconfig - Simplify code. --- MAINTAINERS | 1 + fs/proc/Makefile | 1 + fs/proc/bootconfig.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 fs/proc/bootconfig.c diff --git a/MAINTAINERS b/MAINTAINERS index 836209be1faa..d0da06bdf3d8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15777,6 +15777,7 @@ EXTRA BOOT CONFIG M: Masami Hiramatsu S: Maintained F: lib/bootconfig.c +F: fs/proc/bootconfig.c F: include/linux/bootconfig.h F: tools/bootconfig/* diff --git a/fs/proc/Makefile b/fs/proc/Makefile index ead487e80510..bd08616ed8ba 100644 --- a/fs/proc/Makefile +++ b/fs/proc/Makefile @@ -33,3 +33,4 @@ proc-$(CONFIG_PROC_KCORE) += kcore.o proc-$(CONFIG_PROC_VMCORE) += vmcore.o proc-$(CONFIG_PRINTK) += kmsg.o proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o +proc-$(CONFIG_BOOT_CONFIG) += bootconfig.o diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c new file mode 100644 index 000000000000..9955d75c0585 --- /dev/null +++ b/fs/proc/bootconfig.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * /proc/bootconfig - Extra boot configuration + */ +#include +#include +#include +#include +#include +#include +#include + +static char *saved_boot_config; + +static int boot_config_proc_show(struct seq_file *m, void *v) +{ + if (saved_boot_config) + seq_puts(m, saved_boot_config); + return 0; +} + +/* Rest size of buffer */ +#define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) + +/* Return the needed total length if @size is 0 */ +static int __init copy_xbc_key_value_list(char *dst, size_t size) +{ + struct xbc_node *leaf, *vnode; + const char *val; + char *key, *end = dst + size; + int ret = 0; + + key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); + + xbc_for_each_key_value(leaf, val) { + ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX); + if (ret < 0) + break; + ret = snprintf(dst, rest(dst, end), "%s = ", key); + if (ret < 0) + break; + dst += ret; + vnode = xbc_node_get_child(leaf); + if (vnode && xbc_node_is_array(vnode)) { + xbc_array_for_each_value(vnode, val) { + ret = snprintf(dst, rest(dst, end), "\"%s\"%s", + val, vnode->next ? ", " : "\n"); + if (ret < 0) + goto out; + dst += ret; + } + } else { + ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val); + if (ret < 0) + break; + dst += ret; + } + } +out: + kfree(key); + + return ret < 0 ? ret : dst - (end - size); +} + +static int __init proc_boot_config_init(void) +{ + int len; + + len = copy_xbc_key_value_list(NULL, 0); + if (len < 0) + return len; + + if (len > 0) { + saved_boot_config = kzalloc(len + 1, GFP_KERNEL); + if (!saved_boot_config) + return -ENOMEM; + + len = copy_xbc_key_value_list(saved_boot_config, len + 1); + if (len < 0) { + kfree(saved_boot_config); + return len; + } + } + + proc_create_single("bootconfig", 0, NULL, boot_config_proc_show); + + return 0; +} +fs_initcall(proc_boot_config_init);