Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp377194pxb; Thu, 25 Feb 2021 05:08:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmjbzm84SnnCyYSWFCKpYkr7TLpTLY9IjcgSfLkMfbnlgfm14YNuwKq3EzS7wpz4R2TPAi X-Received: by 2002:a17:906:9259:: with SMTP id c25mr2564684ejx.37.1614258482002; Thu, 25 Feb 2021 05:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614258481; cv=none; d=google.com; s=arc-20160816; b=rza1objHtScU9nltqZwFDacL/kJTLfB4i+mGU01fQeN7hXL0Kfj9vx0/DQ6Uh4YUke vrfVGu4CJvxscZCb8MwyN44/57/j37/vtG0L40L/Yu2GT8CWBgqsi42ODxjBaEK/9agw THvE/3tJK4FYCx1680S5824mpXx6hFXnza/lxIT8KWSLHQ4bPQGFqtkQ9uu36+KGi48+ zjvTPoizXsx0I/QnNp9kWo5js+Kz2fCqwgBhcvi6OSSgb3ikh/PEuraOGM6YBcidQEiy ux5+3w07QbZ6NZRM+vQO7JEPuFmvEKtorBpRa3B0I3Y19rUGgGFoR5lZkBpQlWSgYP93 d3YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aWeulIfFYIzG6I486WozJ+GHzaZrFCGTwPjnQmT375Q=; b=nWUKEqt1shKT9V6wgPVvBu0bQnPKH0q7w0xhRG5BKTPs54CXCLHOrv5tYZI8CWs7+0 wLY+menMmAF8akG3c7UKYdPJSgzdEDzmmLF06V7uDmghRaUJCoaFr47BXs0fLjtTbgvW f/G4nMihzT7/J7eIJ20/HREnGWbPp5/askxBqwQkwIpdY05ehyjkrpUOLZTU5AZaulxS DAM1eUYFjB3Ff/ZhwXLh2WyoI4Nw3qzC9AQgjyBBtTXmUbBhk/GWC12ih8nRQYqjPF+5 RU4186SjXtfS8ZZUzjomFgAu7RXNzmAJdlWdZyzo5mbI/+eKE8QZIwm8g3s0DMnY4k6P +VVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QDTq801H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si4012009edl.468.2021.02.25.05.07.38; Thu, 25 Feb 2021 05:08:01 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QDTq801H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232085AbhBYNAh (ORCPT + 99 others); Thu, 25 Feb 2021 08:00:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:53808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbhBYNAS (ORCPT ); Thu, 25 Feb 2021 08:00:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6EBC64F1E; Thu, 25 Feb 2021 12:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614257976; bh=MsNF8DWYQD/tTk1mZpSeLETJRpSBgEH/y2mRLEnwdkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QDTq801HD7ecpBkv6MP3z/prgHAOpWzQQR3vgFK80pp3ZxM0pZ2gkrbzOdCiceLbA EAk4xo2bZUNgNpgxgBhGiQdfOBx+ag1ZNOhaTG7olQqa1q+TLcVmEydWyzrYcy1WmS qx2rGAbjXt/6n5Q3fG+/pxWl3qMNhBGRzyVNN6KqxCN75Ywh4YDr07kHzsSHJsGdat 8TbNz6cGL+bimscAxUjoNgHgdawirqL2sJlQgt8qjCRusSM/J+QqkAOIMtByAAr+A0 LV+K9S9EC4AcToYZ3dHtdhwjPtu53r+xN5eBuvMnlPb7JatEBlfpYEb5pDyqQr6KZM iwkiopcKjvWQg== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Max Uvarov , Rob Herring , Ard Biesheuvel , Marc Zyngier , Doug Anderson , Tyler Hicks , Frank Rowand , Arnd Bergmann , Palmer Dabbelt , Greg Kroah-Hartman , Catalin Marinas , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH 1/2] arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides Date: Thu, 25 Feb 2021 12:59:20 +0000 Message-Id: <20210225125921.13147-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210225125921.13147-1-will@kernel.org> References: <20210225125921.13147-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The built-in kernel commandline (CONFIG_CMDLINE) can be configured in three different ways: 1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args 2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE 3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't any bootloader args. The early cmdline parsing to detect idreg overrides gets (2) and (3) slightly wrong: in the case of (2) the bootloader args are parsed first and in the case of (3) the CMDLINE is always parsed. Fix these issues by moving the bootargs parsing out into a helper function and following the same logic as that used by the EFI stub. Cc: Marc Zyngier Fixes: 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility") Signed-off-by: Will Deacon --- arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index dffb16682330..cc071712c6f9 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) } while (1); } -static __init void parse_cmdline(void) +static __init const u8 *get_bootargs_cmdline(void) { - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { - const u8 *prop; - void *fdt; - int node; + const u8 *prop; + void *fdt; + int node; - fdt = get_early_fdt_ptr(); - if (!fdt) - goto out; + fdt = get_early_fdt_ptr(); + if (!fdt) + return NULL; - node = fdt_path_offset(fdt, "/chosen"); - if (node < 0) - goto out; + node = fdt_path_offset(fdt, "/chosen"); + if (node < 0) + return NULL; - prop = fdt_getprop(fdt, node, "bootargs", NULL); - if (!prop) - goto out; + prop = fdt_getprop(fdt, node, "bootargs", NULL); + if (!prop) + return NULL; - __parse_cmdline(prop, true); + return strlen(prop) ? prop : NULL; +} - if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND)) - return; +static __init void parse_cmdline(void) +{ + const u8 *prop = get_bootargs_cmdline(); + + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || + IS_ENABLED(CONFIG_CMDLINE_FORCE) || + !prop) { + __parse_cmdline(CONFIG_CMDLINE, true); } -out: - __parse_cmdline(CONFIG_CMDLINE, true); + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop) + __parse_cmdline(prop, true); } /* Keep checkers quiet */ -- 2.30.1.766.gb4fecdf3b7-goog