From patchwork Thu Feb 25 12:59:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12104075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 619B4C433E0 for ; Thu, 25 Feb 2021 13:01:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E4DDE64F0F for ; Thu, 25 Feb 2021 13:01:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4DDE64F0F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6D41Yk+y9UIie5CkIWdyjUCxd2Iuqpymwm67XVyVP/o=; b=Kdxa6UDWEeOeKhqzi2vfDnSHZ wHydwLn4hkYRLth2TjmobZANjV3bjeqWMCWz7gceNuhVQe7V0xRjQOkZ9jTuOH3nmurkukiBxmNhV u/7QnQ9EU1AzOh+yKxDRyOwUs41JedUFM7/HPsXh4RtnHs2Q+uuJe1ECKVI4Unl8IA2K+BlKD8q4Q FS1GPaK8jh+ZxPsn+G7MQJRnsNBleJkS5hGsSYy4o5f+aUqzuzhYeXLGiKjl+7kNdNQXWC414aSHH F0bhQPqoteUO5damo8jWN3oGK4/XRUEsbE7hDz8WgG/p3Yxvc4GvXOzAivy5Uompa3PqyFITFJVeD D5XVRQwBg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFGF1-0007PG-Hv; Thu, 25 Feb 2021 12:59:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFGEy-0007Om-Qa for linux-arm-kernel@lists.infradead.org; Thu, 25 Feb 2021 12:59:37 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210225_075937_083176_414C25BE X-CRM114-Status: GOOD ( 15.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , kernel-team@android.com, Catalin Marinas , Arnd Bergmann , Frank Rowand , devicetree@vger.kernel.org, Marc Zyngier , Doug Anderson , Tyler Hicks , Palmer Dabbelt , Greg Kroah-Hartman , Max Uvarov , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Reviewed-by: Marc Zyngier --- 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 */