Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dibs: Define dibs loopback

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/ [1]
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>

authored by

Alexandra Winter and committed by
Paolo Abeni
cb990a45 26972696

+140 -1
+1
arch/s390/configs/debug_defconfig
··· 121 121 CONFIG_XFRM_USER=m 122 122 CONFIG_NET_KEY=m 123 123 CONFIG_DIBS=y 124 + CONFIG_DIBS_LO=y 124 125 CONFIG_SMC_DIAG=m 125 126 CONFIG_SMC_LO=y 126 127 CONFIG_INET=y
+1
arch/s390/configs/defconfig
··· 112 112 CONFIG_XFRM_USER=m 113 113 CONFIG_NET_KEY=m 114 114 CONFIG_DIBS=y 115 + CONFIG_DIBS_LO=y 115 116 CONFIG_SMC_DIAG=m 116 117 CONFIG_SMC_LO=y 117 118 CONFIG_INET=y
+11
drivers/dibs/Kconfig
··· 10 10 Select this option to provide the abstraction layer between 11 11 dibs devices and dibs clients like the SMC protocol. 12 12 The module name is dibs. 13 + 14 + config DIBS_LO 15 + bool "intra-OS shortcut with dibs loopback" 16 + depends on DIBS 17 + default n 18 + help 19 + DIBS_LO enables the creation of an software-emulated dibs device 20 + named lo which can be used for transferring data when communication 21 + occurs within the same OS. This helps in convenient testing of 22 + dibs clients, since dibs loopback is independent of architecture or 23 + hardware.
+1
drivers/dibs/Makefile
··· 5 5 6 6 dibs-y += dibs_main.o 7 7 obj-$(CONFIG_DIBS) += dibs.o 8 + dibs-$(CONFIG_DIBS_LO) += dibs_loopback.o
+78
drivers/dibs/dibs_loopback.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Functions for dibs loopback/loopback-ism device. 4 + * 5 + * Copyright (c) 2024, Alibaba Inc. 6 + * 7 + * Author: Wen Gu <guwen@linux.alibaba.com> 8 + * Tony Lu <tonylu@linux.alibaba.com> 9 + * 10 + */ 11 + 12 + #include <linux/dibs.h> 13 + #include <linux/slab.h> 14 + #include <linux/types.h> 15 + 16 + #include "dibs_loopback.h" 17 + 18 + /* global loopback device */ 19 + static struct dibs_lo_dev *lo_dev; 20 + 21 + static void dibs_lo_dev_exit(struct dibs_lo_dev *ldev) 22 + { 23 + dibs_dev_del(ldev->dibs); 24 + } 25 + 26 + static int dibs_lo_dev_probe(void) 27 + { 28 + struct dibs_lo_dev *ldev; 29 + struct dibs_dev *dibs; 30 + int ret; 31 + 32 + ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); 33 + if (!ldev) 34 + return -ENOMEM; 35 + 36 + dibs = dibs_dev_alloc(); 37 + if (!dibs) { 38 + kfree(ldev); 39 + return -ENOMEM; 40 + } 41 + 42 + ldev->dibs = dibs; 43 + 44 + ret = dibs_dev_add(dibs); 45 + if (ret) 46 + goto err_reg; 47 + lo_dev = ldev; 48 + return 0; 49 + 50 + err_reg: 51 + /* pairs with dibs_dev_alloc() */ 52 + kfree(dibs); 53 + kfree(ldev); 54 + 55 + return ret; 56 + } 57 + 58 + static void dibs_lo_dev_remove(void) 59 + { 60 + if (!lo_dev) 61 + return; 62 + 63 + dibs_lo_dev_exit(lo_dev); 64 + /* pairs with dibs_dev_alloc() */ 65 + kfree(lo_dev->dibs); 66 + kfree(lo_dev); 67 + lo_dev = NULL; 68 + } 69 + 70 + int dibs_loopback_init(void) 71 + { 72 + return dibs_lo_dev_probe(); 73 + } 74 + 75 + void dibs_loopback_exit(void) 76 + { 77 + dibs_lo_dev_remove(); 78 + }
+38
drivers/dibs/dibs_loopback.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * dibs loopback (aka loopback-ism) device structure definitions. 4 + * 5 + * Copyright (c) 2024, Alibaba Inc. 6 + * 7 + * Author: Wen Gu <guwen@linux.alibaba.com> 8 + * Tony Lu <tonylu@linux.alibaba.com> 9 + * 10 + */ 11 + 12 + #ifndef _DIBS_LOOPBACK_H 13 + #define _DIBS_LOOPBACK_H 14 + 15 + #include <linux/dibs.h> 16 + #include <linux/types.h> 17 + #include <linux/wait.h> 18 + 19 + #if IS_ENABLED(CONFIG_DIBS_LO) 20 + 21 + struct dibs_lo_dev { 22 + struct dibs_dev *dibs; 23 + }; 24 + 25 + int dibs_loopback_init(void); 26 + void dibs_loopback_exit(void); 27 + #else 28 + static inline int dibs_loopback_init(void) 29 + { 30 + return 0; 31 + } 32 + 33 + static inline void dibs_loopback_exit(void) 34 + { 35 + } 36 + #endif 37 + 38 + #endif /* _DIBS_LOOPBACK_H */
+10 -1
drivers/dibs/dibs_main.c
··· 15 15 #include <linux/err.h> 16 16 #include <linux/dibs.h> 17 17 18 + #include "dibs_loopback.h" 19 + 18 20 MODULE_DESCRIPTION("Direct Internal Buffer Sharing class"); 19 21 MODULE_LICENSE("GPL"); 20 22 ··· 98 96 99 97 static int __init dibs_init(void) 100 98 { 99 + int rc; 100 + 101 101 memset(clients, 0, sizeof(clients)); 102 102 max_client = 0; 103 103 104 - return 0; 104 + rc = dibs_loopback_init(); 105 + if (rc) 106 + pr_err("%s fails with %d\n", __func__, rc); 107 + 108 + return rc; 105 109 } 106 110 107 111 static void __exit dibs_exit(void) 108 112 { 113 + dibs_loopback_exit(); 109 114 } 110 115 111 116 module_init(dibs_init);