From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591691EC4DE for ; Sat, 21 Dec 2024 09:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734773960; cv=none; b=jn0IJfqkoIWQD27NddxccabFcEeJl7zDgzt2ucekdDU1uYGuAjN2LsdACbBcxH0rLKHzXgkA4RTB8iJsc5HLfOULCLzeFLvQcHook3Plb1ntrDk3/pGIgaftUkj96vY6UGLIebU88SBuYy4gDEZUMzCT3xhPWYaSebiqGtLdUi4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734773960; c=relaxed/simple; bh=9pXezadzbls94KOnx5e1shcBTjOjycAt9+CEapX5iQc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Cm+aFi2QDVyVF/sJR5ogEDTHe26PhNp5lxXaI+7EM5hn1+l1BY33aEkhF2YE3Hi9hqr21ALpSd1uXnOrSXriaMpILoeib3/MGsZC5jNvJIdZ87rysQEytPcw00Ev7AaYI16WGDWn0rVkokH1UcIa6l5JrAEuyho/Pb+mvIY3J0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=WE4ECmGy; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="WE4ECmGy" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-432d86a3085so18395895e9.2 for ; Sat, 21 Dec 2024 01:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1734773956; x=1735378756; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CZNmeX86n+9HAVwGE3m2ohvACsxbMW0Tp1k1MFwLUd0=; b=WE4ECmGy3hEwhGM6VA6mi09Ba8Y6dGTdngrqFhT40TkPSXuABfvPMqKRLO6BuORupG SNrSJkfKua5DWWPV3v7bKwcS5LWaar41N8bdk6QrJTKW7qst4Isu4ijTysvGmh0hSDfV Atnj6N4mQOA4DoIwVlxFqvW8JAbCRKuovfMfMJ5YYgY+HNT8r2dYswq+8fIDT1vmMiOx UTAcuBGI7lrNPxKYA3K4EWYpfgWVBcUJgmREpOD8idaQ4+lE+5jBFfZLdBEhGHV0Pdxw XHrjPL4TglhDO1IB7c91NOmrdb+lLrn1/38atEePoLkXYZiCvBUvY3PsFvm7aB46/fF1 SqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734773956; x=1735378756; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CZNmeX86n+9HAVwGE3m2ohvACsxbMW0Tp1k1MFwLUd0=; b=b1r5VBX9qZvdDU+KRuqVvx+wQnuD0qV6FQyPljIFuPinfHxEmPPPRpsuv1Kys77Z7e gHuXeVdkkirTDcQlW+80bs0o1lMNdq7awLMj2Cyw7gBA7mOJSo6rK3wLOecyOfCwX2La o3IpzLC6I4p+zoLPEkesiq5Bn7ZZsETW8wHBMSihq8f4a0INEWzADlP6JINhK3/mYXhK hiZ+dzB3X9Ilt351mPZSJPia6iHBO/JHQPPtjEdYS3J2oYkExwwO+eXrJYu1sAzbt2// YA1XFeJ/qxZaovOsZ+dMBth0iwTPF94sJkgYHd7o+h3kiOvP+tmvFYZBOIPPh8x8xIta Ei6Q== X-Forwarded-Encrypted: i=1; AJvYcCXhKYfas8dj+KgHdDp4hdQTumMtKYKaZbvNqLcl4VcwHEjkToH5qmpdraA5PFL8Tv5MulLoqE4RPEkz6UU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0kvETAt5IeQQpRpitmwlIXylrYFCQtZvdgV0pZtx1CwVqhmG8 Nx0x5aS8nHEV2rzYBRM0lg79qDKN5e6/aaJI85QHp4EDYWXIXKTB9dlFSBb/y2o= X-Gm-Gg: ASbGnctHr622d3nVXVGAHcddXbgE9FxFnk0h6G1XFhvcPkcvqikCtZRfbBligQ7i3x3 CvQjgb731ONo8tlOKVeWyw22ILMcrq5c0DvxL8rU81NBKhZs97/m2mbHL6W6sL2eJy0kUsN9fef oU66EBQ/dHN8pnOq9nqrxYWmTOVPhYAyUAWTzG+UsAp1/ompv1KfujQoxE69A8N4gTOd6NhqSES TzNbrOEGCrvBv3vbX5YdoVgf6YnNuh4b/BnwYBlwJsZFowVSM7VVFBBugfJFlRngA== X-Google-Smtp-Source: AGHT+IG8twa3ijqelDvSJmER6b60k1PJMF5eCL0R2PWjIHs59EYuNofh4YiC0RKcXmuH21YXBrNjBQ== X-Received: by 2002:a05:600c:1d07:b0:434:f335:83b with SMTP id 5b1f17b1804b1-43668548780mr49940765e9.5.1734773955002; Sat, 21 Dec 2024 01:39:15 -0800 (PST) Received: from [192.168.50.4] ([82.78.167.102]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656a0b361sm104827355e9.0.2024.12.21.01.39.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 01:39:14 -0800 (PST) Message-ID: Date: Sat, 21 Dec 2024 11:39:12 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFT 5/6] serial: sh-sci: Clean sci_ports[0] after at earlycon exit To: Geert Uytterhoeven Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> <20241204155806.3781200-6-claudiu.beznea.uj@bp.renesas.com> From: Claudiu Beznea Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, Geert, On 19.12.2024 16:26, Geert Uytterhoeven wrote: > Hi Claudiu, > > On Wed, Dec 4, 2024 at 4:58 PM Claudiu wrote: >> From: Claudiu Beznea >> >> The early_console_setup() function initializes sci_ports[0].port with an >> object of type struct uart_port obtained from the struct earlycon_device >> passed as an argument to early_console_setup(). >> >> Later, during serial port probing, the serial port used as earlycon >> (e.g., port A) might be remapped to a different position in the sci_ports[] >> array, and a different serial port (e.g., port B) might be assigned to slot >> 0. For example: >> >> sci_ports[0] = port B >> sci_ports[X] = port A >> >> In this scenario, the new port mapped at index zero (port B) retains the >> data associated with the earlycon configuration. Consequently, after the >> Linux boot process, any access to the serial port now mapped to >> sci_ports[0] (port B) will block the original earlycon port (port A). >> >> To address this, introduce an early_console_exit() function to clean up >> sci_ports[0] when earlycon is exited. >> >> To prevent the cleanup of sci_ports[0] while the serial device is still >> being used by earlycon, introduce the struct sci_port::probing flag and >> account for it in early_console_exit(). >> >> Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") >> Cc: stable@vger.kernel.org >> Signed-off-by: Claudiu Beznea >> --- >> >> Changes since the integrated patch: >> - adjust the commit message to address Geert comments at [1] >> - Introduce the struct sci_port::probing flag to prevent the cleanup >> of sci_ports[0] while the serial device is still being used by earlycon > > Thanks for the update! > >> --- a/drivers/tty/serial/sh-sci.c >> +++ b/drivers/tty/serial/sh-sci.c >> @@ -159,6 +159,7 @@ struct sci_port { >> bool autorts; >> bool tx_occurred; >> bool earlycon; >> + bool probing; > > This is only used in sci_ports[0], so it can be a single global flag, > instead of a flag embedded in each sci_port structure. > >> }; >> >> #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS >> @@ -3386,7 +3387,8 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev, >> static int sci_probe_single(struct platform_device *dev, >> unsigned int index, >> struct plat_sci_port *p, >> - struct sci_port *sciport) >> + struct sci_port *sciport, >> + struct resource *sci_res) >> { >> int ret; >> >> @@ -3433,12 +3435,15 @@ static int sci_probe_single(struct platform_device *dev, >> sciport->port.flags |= UPF_HARD_FLOW; >> } >> >> - ret = uart_add_one_port(&sci_uart_driver, &sciport->port); >> - if (ret) { >> - return ret; >> + if (sci_ports[0].earlycon && sci_ports[0].port.mapbase == sci_res->start) { >> + /* >> + * Skip cleanup up the sci_port[0] in early_console_exit(), this > > Double up > >> + * port is the same as the earlycon one. >> + */ >> + sci_ports[0].probing = true; >> } >> >> - return 0; >> + return uart_add_one_port(&sci_uart_driver, &sciport->port); >> } >> >> static int sci_probe(struct platform_device *dev) >> @@ -3496,7 +3501,7 @@ static int sci_probe(struct platform_device *dev) >> >> platform_set_drvdata(dev, sp); >> >> - ret = sci_probe_single(dev, dev_id, p, sp); >> + ret = sci_probe_single(dev, dev_id, p, sp, res); >> if (ret) >> return ret; >> >> @@ -3579,6 +3584,20 @@ sh_early_platform_init_buffer("earlyprintk", &sci_driver, >> #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON >> static struct plat_sci_port port_cfg; >> >> +static int early_console_exit(struct console *co) >> +{ >> + struct sci_port *sci_port = &sci_ports[0]; >> + >> + /* >> + * Clean the slot used by earlycon. A new SCI device might >> + * map to this slot. >> + */ >> + if (sci_port->earlycon && !sci_port->probing) >> + memset(sci_port, 0, sizeof(*sci_port)); > > Aha, so this clears sci_port.earlycon, too (cfr. my comment on > PATCH 4/6). Still, I don't think this is sufficient: shouldn't > sci_port.earlycon be cleared unconditionally? I remember I had failures with unconditional clear. I'll double check it though and adjust accordingly, if needed. Thank you, Claudiu > >> + >> + return 0; >> +} >> + >> static int __init early_console_setup(struct earlycon_device *device, >> int type) >> { >> @@ -3596,6 +3615,8 @@ static int __init early_console_setup(struct earlycon_device *device, >> SCSCR_RE | SCSCR_TE | port_cfg.scscr); >> >> device->con->write = serial_console_write; >> + device->con->exit = early_console_exit; >> + >> return 0; >> } >> static int __init sci_early_console_setup(struct earlycon_device *device, > > Gr{oetje,eeting}s, > > Geert > > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds