Received: by 10.213.65.68 with SMTP id h4csp1100165imn; Sun, 18 Mar 2018 14:45:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELvwiq1UBeocb9G2xmWYAvDb1emRzCkuHxbI/WOHwXEN3q8+mZDkzBUdibFX+vLNX5Wrpucs X-Received: by 2002:a17:902:51c3:: with SMTP id y61-v6mr1971150plh.355.1521409512591; Sun, 18 Mar 2018 14:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521409512; cv=none; d=google.com; s=arc-20160816; b=zpSm3SkGpiP+QMwWU4st2sNcCQ/EMYEc+CRG1E1txNO1WyP/VLvmJsisV4WnOko7c0 o69ffH/5TS4lxSEC0TTIJSo8nTyRkuNI1c3kULxu7KhQd2DqiIyxDpoxHqjS6ojfyq6o SucTm05fL4sooT3i3tF2ji2Ok2SGXO/jHlPNhhvx30irgvx58Miu/sHyQcGFbirqF9oC bVhd7JKz8lhRPYzMi5QrRS3ohJ/RKq2Or8gPQJUIeMGHSF6Bq3zwttqarGJemZbJPtIL aXWBK36DFrb8dpcmLitiugPagstYCm9eWE3hv2OG6RMlPV67a/ORQ0PyLQLD9Y1xhKlj KnfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=FcSF0lyw6BRLKHNqUmDShMiAcI27YMZ7ersJomgesto=; b=EQB4hhbT5enPxP/1EpT35OSnFJUIEWnjSJ0qlZoFWBgJ6YJBR1bnrJikUPpZdIo53I jPskSSZfIbGI0LcPn7dtaR5bNlS03rKYdFxhTFNU5JmLNtYmSnNNMzeuHjn3dRZiKAV4 uIFkyOKg206NHJ9In7qIJ3FJUO2YoRCM2JYyezrZjM3sbF51V67OzG1UUKjA6Vh5VYlA MrRhO2Mtl2o1Ryi+IEdIYY2bUoL83te7S3cxH7sxGN2yEV8uHWzmyayBc2kqv9/IcOf5 GIMp9AW7M2Q/P21nOUaV4FbQ3mKXppSWjJgQPOydFqEj4lQNsAwCCwzYZWR8fJl6io1E PMzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=nXcqv/32; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si9395154pfx.350.2018.03.18.14.44.58; Sun, 18 Mar 2018 14:45:12 -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=@sifive.com header.s=google header.b=nXcqv/32; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754637AbeCRVma (ORCPT + 99 others); Sun, 18 Mar 2018 17:42:30 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34027 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026AbeCRVm1 (ORCPT ); Sun, 18 Mar 2018 17:42:27 -0400 Received: by mail-pg0-f66.google.com with SMTP id m15so6146681pgc.1 for ; Sun, 18 Mar 2018 14:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=FcSF0lyw6BRLKHNqUmDShMiAcI27YMZ7ersJomgesto=; b=nXcqv/32dAUO2lEtGBjgIZPoTQuA+abMWzuzVvBAgrdggEC58elRTrVbhL8accuCNF OISsF07mRo7OoiNG3eSiyMvi04bGbkh1pjcdSvM6hq+sk+9xcWq3uuz0MEloSNSHA+KG 6/56k9lB5MQ/RXeQRxUdVSXFXUVvJFGuciTu6fd9YaCkA8xxzRkjiJIbzXg2sVyhIKuf QEitRMM59SvFlV+OEG7w54eIr6e/0fPy0ap4hMo8QDBWIC2iHvP3KR5UDjDP8aVPgBJ+ EP5HRUiV9JeFTFCKgePHcdw4qo/Ncec5Yhs09gmIu/AN8H+bEvBQec5kkcrumJiVZeWq L2lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=FcSF0lyw6BRLKHNqUmDShMiAcI27YMZ7ersJomgesto=; b=GdmbbiYGvSWoXtfssHbcqO+rpolCVhMsZKnQjxZTfe2wmp5YXc+3cPzPa3KJn60fgX iv++FUobiy3yXsgquHG4Ie5p2zaU/FFN5lxZUq0p6P56mPncC+bJWVpnxib/LSjXldBx 8S2HmzIFhYX4MZ2X81FnE25KJX2yO1otFtogiyMuT+yVwVds/Q49cL3JbEkEn4xvU0CX p4yUqVx362ENAjpnxCiAjN6AwTiVA/voxT/RQ4k1RDYuIzkp+HC6/63QaDSyxhKk/ssT 06UzmMwvfNOXIZ8814WHCUkUwRj+sna1nY33eIOjlCIdxwFuqlSCav+dZy8s0Ui/ecw+ gKqA== X-Gm-Message-State: AElRT7HzgA3APIWiAqg5yZX5jCHsJOngCXrQBzeweDGxcJxoHzuwfnr5 w7HXCCKr0ZKnAv2BDoVXyBaeDg== X-Received: by 10.98.156.16 with SMTP id f16mr8257681pfe.180.1521409346468; Sun, 18 Mar 2018 14:42:26 -0700 (PDT) Received: from [10.59.24.250] (h98.112.139.40.ip.windstream.net. [40.139.112.98]) by smtp.gmail.com with ESMTPSA id v8sm24683999pfa.32.2018.03.18.14.42.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Mar 2018 14:42:25 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [PATCH] of: Respect CONFIG_CMDLINE{,_EXTENED,_FORCE) with no chosen node From: Michael Clark In-Reply-To: <20180318125150.3i54r7i5edefbhfq@rob-hp-laptop> Date: Sun, 18 Mar 2018 14:42:23 -0700 Cc: Palmer Dabbelt , frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Trung Tran , Moritz Fischer , Wesley Terpstra Content-Transfer-Encoding: quoted-printable Message-Id: References: <20180314163105.8638-1-palmer@sifive.com> <20180318125150.3i54r7i5edefbhfq@rob-hp-laptop> To: Rob Herring X-Mailer: Apple Mail (2.3445.5.20) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 18/03/2018, at 5:51 AM, Rob Herring wrote: >=20 > On Wed, Mar 14, 2018 at 09:31:05AM -0700, Palmer Dabbelt wrote: >> Systems that boot without a chosen node in the device tree should = still >> respect the command lines that are built into the kernel. This patch >> avoids bailing out of the command line argument parsing code when = there >> is no chosen node in the device tree. This is necessary to boot >> straight to a root file system (ie, without an initramfs) >>=20 >> The intent here is that the only functional change is to copy >> CONFIG_CMDLINE into data if both of them are valid (ie, = CONFIG_CMDLINE >> is defined and data is non-null) on systems where there is no chosen >> device tree node. I don't actually know what the return values do so = I >> just preserved them. >>=20 >> Thanks to Trung and Moritz for finding the bug during our ELC = hackathon >> (and providing the first fix), and Michal for suggesting this fix = (which >> is cleaner than what I was doing). I've given this very minimal >> testing: it fixes the RISC-V bug (in conjunction with a patch to move >> from COMMANDLINE_OVERRIDE to COMMANDLINE_FORCE), still works on = systems >> with and without the chosen node, and builds on ARM64. >>=20 >> CC: Michael J Clark >> CC: Trung Tran >> CC: Moritz Fischer >> Signed-off-by: Palmer Dabbelt >> --- >> drivers/of/fdt.c | 14 ++++++++++++-- >> 1 file changed, 12 insertions(+), 2 deletions(-) >>=20 >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c >> index 84aa9d676375..60241b1cb024 100644 >> --- a/drivers/of/fdt.c >> +++ b/drivers/of/fdt.c >> @@ -1084,9 +1084,12 @@ int __init early_init_dt_scan_chosen(unsigned = long node, const char *uname, >>=20 >> pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, = uname); >>=20 >> - if (depth !=3D 1 || !data || >> + if (!data) >> + goto no_data; >=20 > Just "return 0" here. >=20 >> + >> + if (depth !=3D 1 || >> (strcmp(uname, "chosen") !=3D 0 && strcmp(uname, "chosen@0") = !=3D 0)) >> - return 0; >> + goto no_chosen; >>=20 >> early_init_dt_check_for_initrd(node); >>=20 >> @@ -1117,6 +1120,13 @@ int __init early_init_dt_scan_chosen(unsigned = long node, const char *uname, >>=20 >> /* break now */ >> return 1; >> + >> +no_chosen: >> +#ifdef CONFIG_CMDLINE >> + strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); >=20 > Best case, this is going to needlessly copy the string on every single=20= > node that is not /chosen. >=20 > Worst case, I think this changes behavior. For example, first you copy=20= > CONFIG_CMDLINE into data, then on a later iteration, you strlcat=20 > CONFIG_CMDLINE into data if CONFIG_CMDLINE_EXTEND is enable. There = could=20 > also be some unintended behavior if data has a string to start with.=20= >=20 > I'd really like to see this function re-written to just find the = /chosen=20 > node and then handle each property one by one. The iterating approach = is=20 > silly. I assume it predates libfdt and we didn't have nice functions = to=20 > find nodes by path (or any other way). Thanks very much for the feedback. I think we had the right intent, which was to fix the issue in the = generic device tree code rather than add a arch specific hack. = Previously we had code in arch/riscv/kernel/setup.c which would copy the = built-in command line but this clashed with the architecture neutral = code, which resulted in appending the compiled-in command twice if the = chosen node was present in device-tree. I=E2=80=99m adding Wes to the = =E2=80=98cc as he has recently changed the HiFive Unleased device-tree = to include an empty chosen node which is another workaround for the = issue. We weren=E2=80=99t aware that this code was called in a loop for each = device-tree node. I guess one possibility is to hoist the CONFIG_CMDLINE = code out of early_init_dt_scan_chosen into early_init_dt_scan and have = early_init_dt_scan_chosen append bootargs or optionally ignore it if = CONFIG_CMDLINE_OVERRIDE is set. > I'm working on a patch to re-structure this function. Will send it out=20= > in the next day. Thanks! It seems logical that the architecture neutral code should set the = compiled in command-line if CONFIG_CMDLINE_OVERRIDE is set, whether or = not a =E2=80=9Cchosen=E2=80=9D node is present. So we would prefer a fix = in the device-tree code over an architecture specific workaround. The = problem with an architecture specific workaround outside of device-tree = code is that it doesn=E2=80=99t know whether the chosen node is present. = I had previously submitted a patch to remove the architecture specific = command line code because it duplicated code in drivers/of/fdt.c and = resulted in the built-in command being appended twice if the chosen node = was present. It was only later that we became aware that it was not = possible to use the built-in command line if the =E2=80=9Cchosen=E2=80=9D = node was not present. >> +#endif >> +no_data: >> + return 0; >> } >>=20 >> #ifdef CONFIG_HAVE_MEMBLOCK >> --=20 >> 2.16.1