]> www.infradead.org Git - users/hch/misc.git/commitdiff
dibs: Define dibs loopback
authorAlexandra Winter <wintera@linux.ibm.com>
Thu, 18 Sep 2025 11:04:52 +0000 (13:04 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 23 Sep 2025 09:13:21 +0000 (11:13 +0200)
The first stage of loopback-ism was implemented as part of the
SMC module [1]. Now that we have the dibs layer, provide access to a
dibs_loopback device to all dibs clients.

This is the first step of moving loopback-ism from net/smc/smc_loopback.*
to drivers/dibs/dibs_loopback.*. One global structure lo_dev is allocated
and added to the dibs devices. Follow-on patches will move functionality.

Same as smc_loopback, dibs_loopback is provided by a config option.
Note that there is no way to dynamically add or remove the loopback
device. That could be a future improvement.

When moving code to drivers/dibs, replace ism_ prefix with dibs_ prefix.
As this is mostly a move of existing code, copyright and authors are
unchanged.

Link: https://lore.kernel.org/lkml/20240428060738.60843-1-guwen@linux.alibaba.com/
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
Link: https://patch.msgid.link/20250918110500.1731261-7-wintera@linux.ibm.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
arch/s390/configs/debug_defconfig
arch/s390/configs/defconfig
drivers/dibs/Kconfig
drivers/dibs/Makefile
drivers/dibs/dibs_loopback.c [new file with mode: 0644]
drivers/dibs/dibs_loopback.h [new file with mode: 0644]
drivers/dibs/dibs_main.c

index 7bc54f053a3beaf888acc2122e201d0cb7e296a8..5a2ed07b61989d94015cb1461a243cc3bdeb3553 100644 (file)
@@ -121,6 +121,7 @@ CONFIG_UNIX_DIAG=m
 CONFIG_XFRM_USER=m
 CONFIG_NET_KEY=m
 CONFIG_DIBS=y
+CONFIG_DIBS_LO=y
 CONFIG_SMC_DIAG=m
 CONFIG_SMC_LO=y
 CONFIG_INET=y
index 4bf6f3311f7d2c5d9e5628d21beea4528839d72b..4cbdd7e2ff9f65d7c8bb618267a258e5d89051ad 100644 (file)
@@ -112,6 +112,7 @@ CONFIG_UNIX_DIAG=m
 CONFIG_XFRM_USER=m
 CONFIG_NET_KEY=m
 CONFIG_DIBS=y
+CONFIG_DIBS_LO=y
 CONFIG_SMC_DIAG=m
 CONFIG_SMC_LO=y
 CONFIG_INET=y
index 09c12f6838add9e41fe3e9a1776cb11add0d4b8c..5dc347b9b2350667490c382ee9fbb52b5a2d7333 100644 (file)
@@ -10,3 +10,14 @@ config DIBS
          Select this option to provide the abstraction layer between
          dibs devices and dibs clients like the SMC protocol.
          The module name is dibs.
+
+config DIBS_LO
+       bool "intra-OS shortcut with dibs loopback"
+       depends on DIBS
+       default n
+       help
+         DIBS_LO enables the creation of an software-emulated dibs device
+         named lo which can be used for transferring data when communication
+         occurs within the same OS. This helps in convenient testing of
+         dibs clients, since dibs loopback is independent of architecture or
+         hardware.
index 825dec431bfc24d9c3217d93f2d197a6f15ef8bc..85805490c77fe0057e8da1d5637ffddd47c2c99a 100644 (file)
@@ -5,3 +5,4 @@
 
 dibs-y += dibs_main.o
 obj-$(CONFIG_DIBS) += dibs.o
+dibs-$(CONFIG_DIBS_LO) += dibs_loopback.o
\ No newline at end of file
diff --git a/drivers/dibs/dibs_loopback.c b/drivers/dibs/dibs_loopback.c
new file mode 100644 (file)
index 0000000..225514a
--- /dev/null
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Functions for dibs loopback/loopback-ism device.
+ *
+ *  Copyright (c) 2024, Alibaba Inc.
+ *
+ *  Author: Wen Gu <guwen@linux.alibaba.com>
+ *          Tony Lu <tonylu@linux.alibaba.com>
+ *
+ */
+
+#include <linux/dibs.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include "dibs_loopback.h"
+
+/* global loopback device */
+static struct dibs_lo_dev *lo_dev;
+
+static void dibs_lo_dev_exit(struct dibs_lo_dev *ldev)
+{
+       dibs_dev_del(ldev->dibs);
+}
+
+static int dibs_lo_dev_probe(void)
+{
+       struct dibs_lo_dev *ldev;
+       struct dibs_dev *dibs;
+       int ret;
+
+       ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
+       if (!ldev)
+               return -ENOMEM;
+
+       dibs = dibs_dev_alloc();
+       if (!dibs) {
+               kfree(ldev);
+               return -ENOMEM;
+       }
+
+       ldev->dibs = dibs;
+
+       ret = dibs_dev_add(dibs);
+       if (ret)
+               goto err_reg;
+       lo_dev = ldev;
+       return 0;
+
+err_reg:
+       /* pairs with dibs_dev_alloc() */
+       kfree(dibs);
+       kfree(ldev);
+
+       return ret;
+}
+
+static void dibs_lo_dev_remove(void)
+{
+       if (!lo_dev)
+               return;
+
+       dibs_lo_dev_exit(lo_dev);
+       /* pairs with dibs_dev_alloc() */
+       kfree(lo_dev->dibs);
+       kfree(lo_dev);
+       lo_dev = NULL;
+}
+
+int dibs_loopback_init(void)
+{
+       return dibs_lo_dev_probe();
+}
+
+void dibs_loopback_exit(void)
+{
+       dibs_lo_dev_remove();
+}
diff --git a/drivers/dibs/dibs_loopback.h b/drivers/dibs/dibs_loopback.h
new file mode 100644 (file)
index 0000000..fd03b63
--- /dev/null
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *  dibs loopback (aka loopback-ism) device structure definitions.
+ *
+ *  Copyright (c) 2024, Alibaba Inc.
+ *
+ *  Author: Wen Gu <guwen@linux.alibaba.com>
+ *          Tony Lu <tonylu@linux.alibaba.com>
+ *
+ */
+
+#ifndef _DIBS_LOOPBACK_H
+#define _DIBS_LOOPBACK_H
+
+#include <linux/dibs.h>
+#include <linux/types.h>
+#include <linux/wait.h>
+
+#if IS_ENABLED(CONFIG_DIBS_LO)
+
+struct dibs_lo_dev {
+       struct dibs_dev *dibs;
+};
+
+int dibs_loopback_init(void);
+void dibs_loopback_exit(void);
+#else
+static inline int dibs_loopback_init(void)
+{
+       return 0;
+}
+
+static inline void dibs_loopback_exit(void)
+{
+}
+#endif
+
+#endif /* _DIBS_LOOPBACK_H */
index 2f420e077417ac25945d56b0709a378c4e14a6ea..a7e33be361582848702b93ae6e3c82f41fcc2c6a 100644 (file)
@@ -15,6 +15,8 @@
 #include <linux/err.h>
 #include <linux/dibs.h>
 
+#include "dibs_loopback.h"
+
 MODULE_DESCRIPTION("Direct Internal Buffer Sharing class");
 MODULE_LICENSE("GPL");
 
@@ -96,14 +98,21 @@ EXPORT_SYMBOL_GPL(dibs_dev_del);
 
 static int __init dibs_init(void)
 {
+       int rc;
+
        memset(clients, 0, sizeof(clients));
        max_client = 0;
 
-       return 0;
+       rc = dibs_loopback_init();
+       if (rc)
+               pr_err("%s fails with %d\n", __func__, rc);
+
+       return rc;
 }
 
 static void __exit dibs_exit(void)
 {
+       dibs_loopback_exit();
 }
 
 module_init(dibs_init);