Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2014032ybz; Thu, 30 Apr 2020 09:20:26 -0700 (PDT) X-Google-Smtp-Source: APiQypKZifn5Yug5C2ox2yQiABUKeuQeOYWZBvU98XYV62gKVibP6Ojm8zs/kuVO2kCNlBZeU2Ls X-Received: by 2002:a17:906:3709:: with SMTP id d9mr3587719ejc.94.1588263625943; Thu, 30 Apr 2020 09:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588263625; cv=none; d=google.com; s=arc-20160816; b=Ck01jBkBWQs+Qu8zEoTi5U5ITV+07G9L87gAXyIr1eXztOfwU6xFM9EGIJKDSceJt9 4OkESwxiURb685nekTf9VSaWCPeFGzFOKjdPpAi2gDnhVE4fCm7jU21M7BXGkA+0VCWV dlHEBtc6bgU/KP5XfMuVdPZDnBxucyNjVd8LQrv37ov0Zi/+5KJIU1rWcu6KlpN2+ynZ O6KTQ3eh2/cIK2oAtEHG9wAtnrIdLi+UhysHTi66UlXoKYFKw6CU72baFJRkGTckGxoz NAUsPuW8jkcDKgZNibhGsGDHgJuOS47UWzvmgo7hsixDJHpl/gdJ2JBB+yxXt0A4Qvb6 xI+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5bAsvHqWCwGkT9CQd5T/W8xxkcoMDs4/cE7bMjlYKe0=; b=a7DaAj9fD7KhgFFL6ggICZyyBaIA6QkgOBlaknEr92MK8f1geD4lrL9lK5AaTMc+J3 Sa/AiIUttBRP5dL+OY8JzWVyEUKSuYAxBud0eCYOqvKjMIwO5UyCBN8z4WGhpovpPM1D 3FYgiQfNnimUaufP0ZiNf3AcjiQZXCd1LIZRrmLpgkEwIv+MzH7VnQodToeuQR6B0mDb gzUswGomFQaOiTraLF823KaiHNb4cMljza7TJRaB3nOGJtrvFakEMkQTwSL4Zq95OfkJ ojVWZ+Wmk4abSqR9DlMoAglj4HAXe8C1K5V8H1VP49OJQHNlsq77h7VkXUNLlljphinF LzBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gbHXr1KR; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga21si63150ejb.350.2020.04.30.09.20.02; Thu, 30 Apr 2020 09:20:25 -0700 (PDT) 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=@linaro.org header.s=google header.b=gbHXr1KR; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726835AbgD3QSJ (ORCPT + 99 others); Thu, 30 Apr 2020 12:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726420AbgD3QSI (ORCPT ); Thu, 30 Apr 2020 12:18:08 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 786E3C035495 for ; Thu, 30 Apr 2020 09:18:07 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id r26so2626208wmh.0 for ; Thu, 30 Apr 2020 09:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5bAsvHqWCwGkT9CQd5T/W8xxkcoMDs4/cE7bMjlYKe0=; b=gbHXr1KRjKzHoWccXlTIFlKA6SNRGpxXOO+JrrqgTvF8sYDdJfErPMiJJXwfzBd82v +Bp0Fn/5Bb8Gtwik2V1YrWSCqY7eslqiV5SJZQSfWPtOaDewmOSMtwJ7Bzs9PFtODxoR RH7O/FjGUW8detzTpo+wXVG3U2QUMlLmWBYXJF5Eyzv2rUOCusSe4RelyEqOkdYzr16H 13FPv5lrfR0iidWprYTw97a8ojDJa0Zj30usR+mgFPxUKVVsrJ226gWyB4GvZHeCPtwn AEmL2ybLlvTiEIWqjII/JOaclnZlhSDE4LV+MfUFikvplidy4TPP4nHQM016g7+PbXmc 6Q4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5bAsvHqWCwGkT9CQd5T/W8xxkcoMDs4/cE7bMjlYKe0=; b=XzgTr3ZmajG5LOh5uLFLfBSQ7vhOkI7HXpV8xViCoQRzphOxW3TjMKXV+l+CqqYjjX iKfrWgU3DLSP1x6fOIXFLYH71d1+i6tAPqLaREAThZSZ+KWGQLMVtSN3j5VP/nUz+OOl mdZcTtrn5EqZoI8lv2N6RdyiLrqgQNZcoJmFvNNf0VjRqBiBzrDpURxEElnKJZpXtASF R8DHgxEk4EjwTuE/HlwAQdo6MtpShpWan7jqomZMBCY/Ctvw/75bHi5Dpo8LddOSQ4FA eYXMDCOmnkacSIM2Ye6k+ReMNkVjdXdSsudTpcunMe/M4izNWMqyRx9iodSQvl5zoAVS jnOw== X-Gm-Message-State: AGi0PuYeDk+Ejc4synnZDsh6UYsPNEyVd+HrQnxIybenAEvtKwGm5wio UkZUhiYJZm8NbyAqW6iusTMIdw== X-Received: by 2002:a1c:1b88:: with SMTP id b130mr3766023wmb.75.1588263486041; Thu, 30 Apr 2020 09:18:06 -0700 (PDT) Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id y18sm160634wmc.45.2020.04.30.09.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 09:18:05 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson Cc: Daniel Thompson , Jason Wessel , Sumit Garg , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2] serial: kgdboc: Allow earlycon initialization to be deferred Date: Thu, 30 Apr 2020 17:17:41 +0100 Message-Id: <20200430161741.1832050-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200429170804.880720-1-daniel.thompson@linaro.org> References: <20200429170804.880720-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there is no guarantee that an earlycon will be initialized before kgdboc tries to adopt it. Almost the opposite: on systems with ACPI then if earlycon has no arguments then it is guaranteed that earlycon will not be initialized. This patch mitigates the problem by giving kgdboc_earlycon a second chance during console_init(). This isn't quite as good as stopping during early parameter parsing but it is still early in the kernel boot. Signed-off-by: Daniel Thompson --- Notes: v2: Simplified, more robust, runs earlier, still has Doug's recent patchset as a prerequisite. What's not to like? More specifically, based on feedback from Doug Anderson, I have replaced the initial hacky implementation with a console initcall. I also made it defer more aggressively after realizing that both earlycon and kgdboc_earlycon are handled as early parameters (meaning I think the current approach relies on the ordering of drivers/tty/serial/Makefile to ensure the earlycon is enabled before kgdboc tries to adopt it). Finally, my apologies to Jason and kgdb ML folks, who are seeing this patch for the first time. I copied the original circulation list from a patch that wasn't kgdb related and forgot to update. drivers/tty/serial/kgdboc.c | 41 +++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 7aca0a67fc0b..596213272ec3 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -509,6 +509,10 @@ static struct kgdb_io kgdboc_earlycon_io_ops = { .is_console = true, }; +#define MAX_CONSOLE_NAME_LEN (sizeof((struct console *) 0)->name) +static char kgdboc_earlycon_param[MAX_CONSOLE_NAME_LEN] __initdata; +static bool kgdboc_earlycon_late_enable __initdata; + static int __init kgdboc_earlycon_init(char *opt) { struct console *con; @@ -529,7 +533,24 @@ static int __init kgdboc_earlycon_init(char *opt) console_unlock(); if (!con) { - pr_info("Couldn't find kgdb earlycon\n"); + /* + * Both earlycon and kgdboc_earlycon are initialized during + * early parameter parsing. We cannot guarantee earlycon gets + * in first and, in any case, on ACPI systems earlycon may + * defer its own initialization (usually to somewhere within + * setup_arch() ). To cope with either of these situations + * we can defer our own initialization to a little later in + * the boot. + */ + if (!kgdboc_earlycon_late_enable) { + pr_info("No suitable earlycon yet, will try later\n"); + if (opt) + strscpy(kgdboc_earlycon_param, opt, + sizeof(kgdboc_earlycon_param)); + kgdboc_earlycon_late_enable = true; + } else { + pr_info("Couldn't find kgdb earlycon\n"); + } return 0; } @@ -543,8 +564,24 @@ static int __init kgdboc_earlycon_init(char *opt) return 0; } - early_param("kgdboc_earlycon", kgdboc_earlycon_init); + +/* + * This is only intended for the late adoption of an early console. + * + * It is not a reliable way to adopt regular consoles because + * we can not control what order console initcalls are made and + * many regular consoles are registered much later in the boot + * process than the console initcalls! + */ +static int __init kgdboc_earlycon_late_init(void) +{ + if (kgdboc_earlycon_late_enable) + kgdboc_earlycon_init(kgdboc_earlycon_param); + return 0; +} +console_initcall(kgdboc_earlycon_late_init); + #endif /* CONFIG_KGDB_SERIAL_CONSOLE */ module_init(init_kgdboc); base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c prerequisite-patch-id: cbaa70eb783f1f34aec7f5839d1fecbc7616a9f6 prerequisite-patch-id: d7543cdd19fb194ded3361d52818970083efdb06 prerequisite-patch-id: 2238d976451dac9e3ee1bf02a077d633e342aa0c prerequisite-patch-id: 9e4296261b608ee172060d04b3de431a5e370096 prerequisite-patch-id: 2b008e0e14a212072874ecb483d9c6844d161b08 prerequisite-patch-id: f5b692b89c997d828832e3ab27fffb8f770d7b6f prerequisite-patch-id: 851d6f4874aa24540db9d765275ae736e8b2955b prerequisite-patch-id: d3969c2fb7cd320eafebe63d7da270dac5a82fc9 prerequisite-patch-id: e1fc1478b7f75094d263ffc64a9f3528151831cf prerequisite-patch-id: 45fb53996a9f5993e03673c10eebf2834c58307f prerequisite-patch-id: 50ac1ddb52c3cce8b712036f212fdd67d7493112 -- 2.25.1