3434#include <irq_kern.h>
3535#include <init.h>
3636#include <os.h>
37+ #include "mconsole_kern.h"
3738#include "vhost_user.h"
3839
3940#define MAX_SUPPORTED_QUEUE_SIZE 256
@@ -1282,6 +1283,7 @@ static struct device vu_cmdline_parent = {
12821283 .release = vu_cmdline_release_dev ,
12831284};
12841285
1286+ static DEFINE_MUTEX (vu_cmdline_lock );
12851287static bool vu_cmdline_parent_registered ;
12861288static int vu_cmdline_id ;
12871289
@@ -1309,7 +1311,7 @@ static void vu_conn_broken(struct work_struct *wk)
13091311 vu_unregister_cmdline_device (& pdata -> pdev -> dev , NULL );
13101312}
13111313
1312- static int vu_cmdline_set (const char * device , const struct kernel_param * kp )
1314+ static int vu_cmdline_set_device (const char * device )
13131315{
13141316 const char * ids = strchr (device , ':' );
13151317 unsigned int virtio_device_id ;
@@ -1321,6 +1323,8 @@ static int vu_cmdline_set(const char *device, const struct kernel_param *kp)
13211323 if (!ids || ids == device )
13221324 return - EINVAL ;
13231325
1326+ guard (mutex )(& vu_cmdline_lock );
1327+
13241328 processed = sscanf (ids , ":%u%n:%d%n" ,
13251329 & virtio_device_id , & consumed ,
13261330 & vu_cmdline_id , & consumed );
@@ -1366,6 +1370,11 @@ static int vu_cmdline_set(const char *device, const struct kernel_param *kp)
13661370 return err ;
13671371}
13681372
1373+ static int vu_cmdline_set (const char * device , const struct kernel_param * kp )
1374+ {
1375+ return vu_cmdline_set_device (device );
1376+ }
1377+
13691378static int vu_cmdline_get_device (struct device * dev , void * data )
13701379{
13711380 struct platform_device * pdev = to_platform_device (dev );
@@ -1380,6 +1389,8 @@ static int vu_cmdline_get_device(struct device *dev, void *data)
13801389
13811390static int vu_cmdline_get (char * buffer , const struct kernel_param * kp )
13821391{
1392+ guard (mutex )(& vu_cmdline_lock );
1393+
13831394 buffer [0 ] = '\0' ;
13841395 if (vu_cmdline_parent_registered )
13851396 device_for_each_child (& vu_cmdline_parent , buffer ,
@@ -1403,6 +1414,8 @@ __uml_help(vu_cmdline_param_ops,
14031414
14041415static void vu_unregister_cmdline_devices (void )
14051416{
1417+ guard (mutex )(& vu_cmdline_lock );
1418+
14061419 if (vu_cmdline_parent_registered ) {
14071420 device_for_each_child (& vu_cmdline_parent , NULL ,
14081421 vu_unregister_cmdline_device );
@@ -1411,6 +1424,42 @@ static void vu_unregister_cmdline_devices(void)
14111424 }
14121425}
14131426
1427+ static int vu_mc_config (char * str , char * * error_out )
1428+ {
1429+ if (* str != '=' ) {
1430+ * error_out = "Invalid config" ;
1431+ return - EINVAL ;
1432+ }
1433+ str += 1 ;
1434+ return vu_cmdline_set_device (str );
1435+ }
1436+
1437+ static int vu_mc_id (char * * str , int * start_out , int * end_out )
1438+ {
1439+ return - EOPNOTSUPP ;
1440+ }
1441+
1442+ static int vu_mc_remove (int n , char * * error_out )
1443+ {
1444+ return - EOPNOTSUPP ;
1445+ }
1446+
1447+ static struct mc_device virtio_uml_mc = {
1448+ .list = LIST_HEAD_INIT (virtio_uml_mc .list ),
1449+ .name = "virtio_uml.device" ,
1450+ .config = vu_mc_config ,
1451+ .get_config = NULL ,
1452+ .id = vu_mc_id ,
1453+ .remove = vu_mc_remove ,
1454+ };
1455+
1456+ static int __init virtio_uml_mc_init (void )
1457+ {
1458+ mconsole_register_dev (& virtio_uml_mc );
1459+ return 0 ;
1460+ }
1461+ late_initcall (virtio_uml_mc_init );
1462+
14141463/* Platform driver */
14151464
14161465static const struct of_device_id virtio_uml_match [] = {
0 commit comments