From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr2-f37.google.com (mail-wr2-f37.google.com [74.125.225.101]) (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 7A08F3839AC for ; Tue, 22 Sep 2026 07:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790062006; cv=none; b=V3O7ZlhoPFmRUfJCot2OvMe4xppAD1oWEYnkdBuF9DPvMY3kUK/ZAp9ATw0POttXVWYVj1ZMh5ClLi3UbFBYmME3gNHGFcQg/1ahXd6C+igauzKSB4NaIxuJ/PwbjOf8nW+gLcoZNt+8s46cwOLKOJqn0AoRIZuLy98eK/v40Wo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790062006; c=relaxed/simple; bh=4Z62Xv5PMHnfdSbbUYiP/gr3VyxZoYSTSx4wDC2uPe8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8JMQvO672XH7AQiiLzWLQXnKNjfY2RzoKGVhVSPaKOV0yI0sfThV+4GLIZKgEF+sA9jYfHJESTI5MGa8o8mlVqH7dW5KYazWceT5nFxK1pG5IHrUyCuUDSPDAf8NoagyKajx48xIMJBDmHEUcTyv3MZ57jPErLq7YbaNdOgkz0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RfVhhZr/; arc=none smtp.client-ip=74.125.225.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RfVhhZr/" Received: by mail-wr2-f37.google.com with SMTP id ffacd0b85a97d-482f6356f6bso2912686f8f.2 for ; Tue, 22 Sep 2026 00:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1790062003; x=1790666803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mijCsOeT4dW/QaoqrTcbYmQViveRxBniaswO81wBCMI=; b=RfVhhZr/6f/blD4HsgpAaq+LoKZI+yFQh38j8flKgtzR7KwCF/rwHFfuNmEMs5kxKr aZ+RLgpc/bS7sdsLKzw4MvgRtKKFiP480nivJ4VQJEoPJIHppz1+mWgwn3UFHZEZ6iWc bmCRk4JNTjO5zgczDAhpbL57XkHbbuaJusDUIEeWPt6hCtvaUhoBo5LX5zlZyZP6eumh cC/Tqu0fRWn3583Qvws4c/1vXs+fhNLpN9UQ5URuipO/sVnTdIRkdy51PQ9UOw8X2eRZ 7TrVBs/RMpBHMfcckSttRyln2ayR7YXl8eYTXjLVa1gR4C+8OdLoI+A2oo8hWjYJJoT4 VG4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790062003; x=1790666803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mijCsOeT4dW/QaoqrTcbYmQViveRxBniaswO81wBCMI=; b=tnINWNS/T6gG/e7wjhfUQPrHvA88OgYhakXqVFRS6YFr0Y1svjF8ltw9BSUIDTYSxH ytUoRNg3K+BnHicjogJJb6HfpA4zx3ecg6FsonhjhffOYFPw6wD0C+hlmr4ihZeLbrhO zndlzJZOguVJ3Yx1d5MAgr2gHjp4tJXLIeIOvPB3XQfsFRujG8LFEEG+IyIEAyBZBNiT OTeSUmbQripuoev1eMgS+xU8w3Z0cfhZaZ0oxvEnEyUQ4Fxjnb0asxs2xF03E6OOL+np frfBoMiVZqmXh/4uBU6b+dSPdYBzUysi0pux7Byt2WFweW98oEe3U41OwWy4O+zKC/8e m1+w== X-Forwarded-Encrypted: i=1; AKwUvBzXJtlhI6xB5SAtGsb8OVu1nZYEULNLv/j0odwy3V3eevttCwPnOQgJM4XlIYAUNwiOoISPV7cDxws/Cyg=@vger.kernel.org X-Gm-Message-State: AFuF++ntxisotjNjd/d2J5sk7LbEn5VmrbPBlCPXhXdEgd3H5kf133jI /Cn8TgUd5J2CrNqHAFjZ8kQaY77YvT8ouKXlvfQTYLso9J4O8TfL9mCLV3oIkOET1CQ= X-Gm-Gg: AYBFou0X4du6cquovPhDMPjpGOD9wbXN5dOlblcZxGukssHXSg2yZymyHtM/uxxnj+e 1y0mRi2DcmxTkI1qE5oy+o9bjPxeL8gepRGJwPpEwwTAb0S5WSJi38UWg3eHhAa3FAHA9NrjgEt BQunJDJlpQ3y5X6OhYGBZec3SGNZlApwX72CunQVJb6JtfnxNImUCoV2LoPhGsr16ws0CFB1RCR 0Nqoy4gqFvp8Jq7rkaElt8/6k9T17Gd/ykPo7RsgM86Q51Z1wXLTwt6l+eWrAWxxtt/elW1SZ0J +mQpFea9IuPquHdmTOVfuJy37jMrHn+FpdJRYb+AtNADco+BZofaSDRb5SSZt7Qx4Zpd+nJqxlk ysJESgrgW2L6X68tVb0YXG40L2IMw022jasH0PPacNzFhlt7/iv/JDiFarWIUemeXgm6LMbCRvw oI8It/kZdfWLZDtsbhFLavxMH7GJuIf42rckVIGe5645Ue9brZrpklGHpyJvylrdHB2fiqBA5o X-Received: by 2002:a05:6000:38f:b0:487:27f9:83d with SMTP id ffacd0b85a97d-48727f90ba9mr11598775f8f.50.1790062002655; Tue, 22 Sep 2026 00:26:42 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48862773ff0sm2915327f8f.9.2026.09.22.00.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 00:26:42 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Samuel Thibault , Greg Kroah-Hartman , Jiri Slaby , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hugo Villeneuve , Fushuai Wang , Kees Cook , Stepan Ionichev , linux-serial@vger.kernel.org, Manuel Lauss , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH 2/2] braille: nbcon: Use nbcon atomic console callbacks Date: Tue, 22 Sep 2026 09:25:58 +0200 Message-ID: <20260922072558.98854-3-pmladek@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922072558.98854-1-pmladek@suse.com> References: <20260922072558.98854-1-pmladek@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The Braille console is integrated with the virtual terminal (VT) and writes its data using the legacy con->write() callback of the associated serial console driver. However, once the underlying console driver is converted to the NBCON API, it should use the con->write_atomic() callback, which must be synchronized by acquiring the nbcon console context. Adapt braille_write() to handle NBCON consoles: 1. Acquire the nbcon console ownership using NBCON_PRIO_EMERGENCY priority before printing, disabling local interrupts to prevent any nested calls into the driver. 2. Call the con->write_atomic() callback to write the buffer. 3. Release the nbcon console ownership and restore local interrupts. Also, adjust __serial8250_console_write() in the 8250 serial driver to exclude Braille consoles from the newline prepending logic. The serial port is not used for standard printk logging which might be interrupted in the middle of the operation. In the Braille mode, the serial driver is supposed to write exactly what it gets. In fact, it does not print any newlines at all in this case. Fixes: d3539347022a ("serial: 8250: Switch to nbcon console, take 2") Signed-off-by: Petr Mladek --- .../accessibility/braille/braille_console.c | 38 ++++++++++++++++++- drivers/tty/serial/8250/8250_port.c | 5 ++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c index 06b43b678d6e..cd1019d478db 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -62,14 +62,32 @@ static void braille_write(u16 *buf) { static u16 lastwrite[WIDTH]; unsigned char data[1 + 1 + 2*WIDTH + 2 + 1], csum = 0, *c; + struct nbcon_write_context wctxt = { }; + unsigned long flags; + u16 out; int i; if (!braille_co) return; + if (braille_co->flags & CON_NBCON) { + /* + * Braille console might be called from unknown context via + * vt_console_print() from console_unlock() from printk(). + * Use the atomic callback and synchronize it just using + * the console context. Disable interrupts to prevent a nested + * call into the driver code which might cause a deadlock when + * trying to acquire the console ownership, see + * __nbcon_atomic_flush_pending_con(). + */ + local_irq_save(flags); + while (!nbcon_braille_try_acquire(braille_co, &wctxt)) + cpu_relax(); + } + if (!memcmp(lastwrite, buf, WIDTH * sizeof(*buf))) - return; + goto release_nbcon; memcpy(lastwrite, buf, WIDTH * sizeof(*buf)); #define SOH 1 @@ -102,7 +120,23 @@ static void braille_write(u16 *buf) *c++ = csum; *c++ = ETX; - braille_co->write(braille_co, data, c - data); + if (braille_co->flags & CON_NBCON) { + if (braille_co->write_atomic && + !braille_co->flags & CON_NBCON_ATOMIC_UNSAFE) { + nbcon_write_context_set_buf(&wctxt, (char *)data, c - data); + braille_co->write_atomic(braille_co, &wctxt); + } else { + pr_warn_once("Braille requires a safe braille_co->write_atomic callback\n"); + } + } else { + braille_co->write(braille_co, data, c - data); + } + +release_nbcon: + if (braille_co->flags & CON_NBCON) { + nbcon_braille_release(&wctxt); + local_irq_restore(flags); + } } /* Follow the VC cursor*/ diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 38fa45e74a37..6eb0b439e433 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -3417,8 +3417,11 @@ static void __serial8250_console_write(struct uart_8250_port *up, * If the console printer did not fully output the previous line, it * must have been handed or taken over. Insert a newline in order to * maintain clean output. + * + * Braille consoles are an exception. The serial port is not used + * for printk(). The driver is supposed to write exactly what it gets. */ - if (!up->console_line_ended) { + if (unlikely(!up->console_line_ended && !nbcon_is_braille(wctxt))) { if (use_fifo) __serial8250_console_fifo_write(up, wctxt, "\n", 1); else -- 2.55.0