Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1913441pxf; Sat, 13 Mar 2021 01:32:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7CGNJQ1211I7K1shGjMyAjEQl3GHB5qzjpq2JVtrWFA8Pz1rpWxrvBAqqqmAcH9+RREa6 X-Received: by 2002:a17:906:d8d3:: with SMTP id re19mr13263186ejb.440.1615627943812; Sat, 13 Mar 2021 01:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615627943; cv=none; d=google.com; s=arc-20160816; b=bhyij9vtkXV5mLi/4mOyRYac9a6MInDYUr9HbU4Yh8KDTEHocp3UO/s7uqITsXdsu8 fbhVBtm7hbnphEc9mzz79pVT4JXvkjPCYeQnYadFh7JZl50MCS/jFuln9yCdIgfqRYyW tRsWBRADAs6D2Y6Q34NZZN5KDwPLfZUlLGTUTmlKaZ8FBIh7z2nOcbWJNWe9zsIMGhat LJ0wMCJCG4UZNH1880rdVjiK8cb6VnGDvl+qgVwFE3e2u1dVMVISmfjNgez0LlWtjBWl v2elzQ06J5DI4TvVYx3Czm+SLv4prRlGqplDW7kLu6rOzh4NSsqV3WqpPxGvX0xzqzaR 1FTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=8oGCyEJ1cldsp+jK3HzV00suQf3KaOSV7fG2O2PZqrY=; b=ddz+6pJ2RQHwfLVByc5ZHtpmZkuow2zWuVoKq5FEEbBPFjocU6lgJurTw4u4vt9sxU f+vN7J5K4MZlsT4hYxaF7hT0ulLS42HYOjAdVzA50zOUzyAu/hfMWLQx+W8lcZ9mSv0e KUwr5GnlmYyz3H0g/F5Gt56Dtmx2VcoH5FPSqRlsfXl1TsPNpeLJBXHAzxbsD34wKoZ6 VMhow2mMHVWzOZ92CthtjdO4sEtX1tc0PTafy1dGH6sMZ7rWdiJoJUP1g3WxiNkcbnfW WK5d+9AUje5gi69wOIxs4KEpAXLNvalisjqLJnQMVTU/ffi23qKuQ2QDlC7+KbwWjCZM osDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si5960366ejx.73.2021.03.13.01.32.01; Sat, 13 Mar 2021 01:32:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233450AbhCMJaA (ORCPT + 99 others); Sat, 13 Mar 2021 04:30:00 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:30934 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233110AbhCMJ3h (ORCPT ); Sat, 13 Mar 2021 04:29:37 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DyHSp14h4z9tvr3; Sat, 13 Mar 2021 10:29:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id zaAMf4DmfJvl; Sat, 13 Mar 2021 10:29:30 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DyHSn63HLz9tvr2; Sat, 13 Mar 2021 10:29:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D50A08B769; Sat, 13 Mar 2021 10:29:30 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Wc7bhFyTgWK9; Sat, 13 Mar 2021 10:29:30 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E04948B75B; Sat, 13 Mar 2021 10:29:29 +0100 (CET) Subject: Re: [PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line To: Daniel Walker Cc: Will Deacon , Rob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, xe-linux-external@cisco.com, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Ruslan Ruslichenko , Ruslan Bilovol , linux-kernel@vger.kernel.org References: <20210309000247.2989531-5-danielwa@cisco.com> <20210309214051.GS109100@zorba> From: Christophe Leroy Message-ID: <3cabc11d-96d1-962c-ab11-43a8c6d00657@csgroup.eu> Date: Sat, 13 Mar 2021 10:29:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210309214051.GS109100@zorba> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 09/03/2021 à 22:40, Daniel Walker a écrit : > On Tue, Mar 09, 2021 at 08:56:47AM +0100, Christophe Leroy wrote: >> >> So we are referencing a function that doesn't exist (namely prom_strlcat). >> But it works because cmdline_add_builtin_custom() looks like a function but >> is in fact an obscure macro that doesn't use prom_strlcat() unless >> GENERIC_CMDLINE_NEED_STRLCAT is defined. >> >> IMHO that's awful for readability and code maintenance. > > powerpc is a special case, there's no other users like this. The reason is > because of all the difficulty in this prom_init.c code. A lot of the generic > code has similar kind of changes to work across architectures. > I'd suggest the following (sorry if Thunderbird damages whitespaces, you'll get the idea anyway) diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h new file mode 100644 index 000000000000..30b9eefc802f --- /dev/null +++ b/include/linux/cmdline.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CMDLINE_H +#define _LINUX_CMDLINE_H + +#ifdef CONFIG_GENERIC_CMDLINE + +#ifndef cmdline_strlcpy +#define cmdline_strlcpy strlcpy +#endif +#ifndef cmdline_strlcat +#define cmdline_strlcat strlcat +#endif + +static __always_inline void +cmdline_add_builtin_custom(char *dest, const char *src, char *tmp, unsigned long length) +{ + if (WARN_ON(sizeof(CONFIG_CMDLINE_PREPEND) > 1 && + !IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) && + !tmp && src == dest)) + return; + + if (sizeof(CONFIG_CMDLINE_PREPEND) > 1 && + !IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) && src == dest) + cmdline_strlcpy(tmp, src, length); + else + tmp = (char *)src; + + cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " ", length); + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) && tmp) + cmdline_strlcat(dest, tmp, length); + cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length); +} + +#define cmdline_add_builtin(dest, src, length) do { \ + static __init char cmdline_tmp[length]; \ + \ + cmdline_add_builtin_custom(dest, src, cmdline_tmp, length); \ +} while (0) + +#endif /* CONFIG_GENERIC_CMDLINE */ + +#endif /* _LINUX_CMDLINE_H */ diff --git a/init/Kconfig b/init/Kconfig index 22946fe5ded9..aeb134f0703b 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2035,6 +2035,27 @@ config PROFILING config TRACEPOINTS bool +config GENERIC_CMDLINE + bool + +if GENERIC_CMDLINE + +config CMDLINE_BOOL + bool "Built-in kernel command line" + +config CMDLINE_APPEND + string "Built-in kernel command string append" if CMDLINE_BOOL + default "" + +config CMDLINE_PREPEND + string "Built-in kernel command string prepend" if CMDLINE_BOOL + default "" + +config CMDLINE_OVERRIDE + bool "Built-in command line overrides boot loader arguments" if CMDLINE_BOOL + +endif + endmenu # General setup source "arch/Kconfig" -- Then on powerpc you do: diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index 2c2f33155317..1649787c3953 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -152,7 +152,7 @@ static struct prom_t __prombss prom; static unsigned long __prombss prom_entry; static char __prombss of_stdout_device[256]; -static char __prombss prom_scratch[256]; +static char __prombss prom_scratch[COMMAND_LINE_SIZE]; static unsigned long __prombss dt_header_start; static unsigned long __prombss dt_struct_start, dt_struct_end; @@ -770,6 +770,12 @@ static unsigned long prom_memparse(const char *ptr, const char **retptr) * Early parsing of the command line passed to the kernel, used for * "mem=x" and the options that affect the iommu */ + +#define cmdline_strlcpy prom_strlcpy +#define cmdline_strlcat prom_strlcat + +#include + static void __init early_cmdline_parse(void) { const char *opt; @@ -780,12 +786,11 @@ static void __init early_cmdline_parse(void) prom_cmd_line[0] = 0; p = prom_cmd_line; - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0) + if ((long)prom.chosen > 0) l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); - if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0') - prom_strlcat(prom_cmd_line, " " CONFIG_CMDLINE, - sizeof(prom_cmd_line)); + cmdline_add_builtin_custom(prom_cmd_line, (l > 0 ? p : NULL), + prom_scratch, sizeof(prom_cmd_line)); prom_printf("command line: %s\n", prom_cmd_line); -- 2.25.0 Christophe