From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9FC92E6CDF for ; Mon, 8 Dec 2025 09:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765185319; cv=none; b=nF+JxCCQAMz35m+4L8jjPz8tQaZEmVww92QSmDFuSBhP42DcRTcQkwk+ZedKg5+i51D2HemN71LvSF8YSnRuwTfjYNOZHKadGlpzELYgWZ3xYTL04zxPkcSqLBl/lWe18PXc7Vs6kWjK/E9gH8sDS//k2tQU0no3QoSP+7yRKmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765185319; c=relaxed/simple; bh=+UDABDK5oT5mm6BjOvg9ufOZQ+2eLTRsYSoF8tWSgD8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=SBmFHh6wHsOYNGWXs+0G0jg3/iiW23UitrgpVO3B+Z0Gqov9rJGHuRPhAabnohdvY6Dy/k2drojLUulsGXf4utisV6VVAf97pe1aQRUGFgNJpsb5k8OYvDcJB+uOpQtJeUP0mxzfsPJaoM9EMNKbmklOM8jjpNNd5QOTir3M2rQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Vet4tKpz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=icAt+9xy; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Vet4tKpz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="icAt+9xy" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1765185310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n0jRbSlBTOXu2/tDJqIVP7A5AUUkIhUtdNCjtPJOucg=; b=Vet4tKpzgQ2NxVGhkR9sNrAITf4mNmOIGNtY1/BoMQS94AWN03etULwwdktBBQpGEiIEZ9 v0XN7wt3XdfDwNWkrjY9AblNQoUZzTaGxR2xJhT2wztqncUMElVYRe0mQfynsvSfwR4jYG 796fnq+C+EufuSozCMsGBnjTOukV9uEAz0ub5ID5+2QCaf1Jti3J1x4UV88uLU+QEX6pCQ isdwvUr1Cn0XJVM1giuVQf7pQgwazTWvqBeecC8ZGfYbfgcxR1JiD7IYy1Ki6GWPlxbEBu F6w5h5tIk4JPINFfLh85cM/c+IqWS9PF4qWrZs8VaercHz7PP9D2UXWO634WUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1765185310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n0jRbSlBTOXu2/tDJqIVP7A5AUUkIhUtdNCjtPJOucg=; b=icAt+9xyYrOzwhrSMwg9DcRVaoDGtnXC2xOsSmUMBlKQLAWngZXyzjBZbU1/5NeC4UKQEd 6j7BoV7qlCMtfKAQ== To: Marcos Paulo de Souza , Petr Mladek , Steven Rostedt , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, marcos@mpdesouza.com, Marcos Paulo de Souza Subject: Re: [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks In-Reply-To: <20251205-nbcon-device-cb-fix-v1-1-906bdff5760b@suse.com> References: <20251205-nbcon-device-cb-fix-v1-1-906bdff5760b@suse.com> Date: Mon, 08 Dec 2025 10:21:09 +0106 Message-ID: <87ecp5wd0i.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2025-12-05, Marcos Paulo de Souza wrote: > These callbacks are necessary to synchronize ->write_thread callback > against other operations using the same device. > > Signed-off-by: Marcos Paulo de Souza > --- > I found this issue while creating a custom kernel module that implements > the nbcon interfaces. > --- > kernel/printk/nbcon.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c > index 3fa403f9831f..02809c44d7ea 100644 > --- a/kernel/printk/nbcon.c > +++ b/kernel/printk/nbcon.c > @@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con) > if (WARN_ON(!con->write_thread)) > return false; > > + /* The device_lock() and device_unlock() callbacks are mandatory. */ > + if (WARN_ON(!con->device_lock || !con->device_unlock)) > + return false; > + The code itself is fine and this is an important contribution. But I would prefer to combine it with the previous mandatory check. So it looks more like this: diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 3fa403f9831f..f096282b0625 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1760,9 +1758,12 @@ bool nbcon_alloc(struct console *con) /* Synchronize the kthread start. */ lockdep_assert_console_list_lock_held(); - /* The write_thread() callback is mandatory. */ - if (WARN_ON(!con->write_thread)) + /* Check for mandatory nbcon callbacks. */ + if (WARN_ON(!con->write_thread || + !con->device_lock || + !con->device_unlock)) { return false; + } rcuwait_init(&con->rcuwait); init_irq_work(&con->irq_work, nbcon_irq_work); John Ogness