lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230601154612.GE14287@atomide.com>
Date:   Thu, 1 Jun 2023 18:46:12 +0300
From:   Tony Lindgren <tony@...mide.com>
To:     Marek Szyprowski <m.szyprowski@...sung.com>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jirislaby@...nel.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Andy Shevchenko <andriy.shevchenko@...el.com>,
        Dhruva Gole <d-gole@...com>,
        Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
        John Ogness <john.ogness@...utronix.de>,
        Johan Hovold <johan@...nel.org>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        Vignesh Raghavendra <vigneshr@...com>,
        linux-omap@...r.kernel.org, linux-serial@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] serial: core: Fix probing serial_base_bus devices

* Marek Szyprowski <m.szyprowski@...sung.com> [230601 15:09]:
> On 01.06.2023 16:21, Greg Kroah-Hartman wrote:
> > On Thu, Jun 01, 2023 at 05:14:44PM +0300, Tony Lindgren wrote:
> >> If a physical serial port device driver uses arch_initcall() we fail to
> >> probe the serial_base_bus devices and the serial port tx fails. This is
> >> because as serial_base_bus uses module_initcall().
> >>
> >> Let's fix the issue by changing serial_base_bus to use arch_initcall().
> > This will only work if the linking order is such that this will always
> > come before the drivers.  Is that the case here?
> 
> Yes, serial_base_bus is linked as a second object, just after the 
> serial_core. Device drivers come later.

If we don't want to rely on the Makefile order here, we could do something
like the patch below.

Regards,

Tony

8< ---------------------
diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c
--- a/drivers/tty/serial/serial_base_bus.c
+++ b/drivers/tty/serial/serial_base_bus.c
@@ -11,12 +11,18 @@
 #include <linux/container_of.h>
 #include <linux/device.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/serial_core.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 
 #include "serial_base.h"
 
+static bool serial_base_initialized;
+static DEFINE_MUTEX(serial_base_lock);
+
+static int serial_base_init(void);
+
 static int serial_base_match(struct device *dev, struct device_driver *drv)
 {
 	int len = strlen(drv->name);
@@ -48,6 +54,12 @@ static int serial_base_device_init(struct uart_port *port,
 				   void (*release)(struct device *dev),
 				   int id)
 {
+	/*
+	 * Initialize bus if not yet initialized. Some drivers are using
+	 * arch_initcall()
+	 */
+	serial_base_init();
+
 	device_initialize(dev);
 	dev->type = type;
 	dev->parent = parent_dev;
@@ -163,6 +175,14 @@ static int serial_base_init(void)
 {
 	int ret;
 
+	mutex_lock(&serial_base_lock);
+
+	/* Also called from serial_base_device_init() in some cases */
+	if (serial_base_initialized) {
+		ret = 0;
+		goto out_unlock;
+	}
+
 	ret = bus_register(&serial_base_bus_type);
 	if (ret)
 		return ret;
@@ -175,6 +195,10 @@ static int serial_base_init(void)
 	if (ret)
 		goto err_ctrl_exit;
 
+	serial_base_initialized = true;
+
+	mutex_unlock(&serial_base_lock);
+
 	return 0;
 
 err_ctrl_exit:
@@ -183,15 +207,21 @@ static int serial_base_init(void)
 err_bus_unregister:
 	bus_unregister(&serial_base_bus_type);
 
+out_unlock:
+	mutex_unlock(&serial_base_lock);
+
 	return ret;
 }
 module_init(serial_base_init);
 
 static void serial_base_exit(void)
 {
+	mutex_lock(&serial_base_lock);
 	serial_base_port_exit();
 	serial_base_ctrl_exit();
 	bus_unregister(&serial_base_bus_type);
+	serial_base_initialized = false;
+	mutex_unlock(&serial_base_lock);
 }
 module_exit(serial_base_exit);
 
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ