cobalt/rtdm: allow for device teardown
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 245 lines · Philippe Gerum via Xenomai
Currently,
rtdm_dev_unregister()will hang soft until all references on the dismantled device have been dropped, which in turn cannot happen until allrtdm_fdson the device have been closed, which cannot happen until all references on those fds have been dropped eventually. Unfortunately, applications have no indication that such teardown has been requested, and keep sleeping on I/O channels managed by the dismantled device, which preventsrtdm_dev_unregister()from completing.Allow for orderly device teardown by tracking all file descriptors representing connections active on a device, forcing each of them down by calling the driver's
close()handler fromrtdm_dev_unregister(). Since aclose()handler should abort any ongoing I/O operation on the channel being dismantled, any blocking I/O call on such channel should return on error with no additional change to the existing drivers. The common error code indicating an aborted I/O operation in this case is EBADF.Upon receiving the error, the application is expected to close the stale file descriptor and/or exit, which would drop the corresponding file reference.
Stale file descriptors lingering in applications will still prevent driver modules serving them from unloading until they are eventually closed. Subsequent operations on a file descriptor connected to a device which is being torn now down lead to the EBADF error.
Signed-off-by Philippe Gerum <[email protected]>--- include/cobalt/kernel/list.h | 2 +- include/cobalt/kernel/rtdm/driver.h | 1 + include/cobalt/kernel/rtdm/fd.h | 2 ++ kernel/cobalt/rtdm/core.c | 25 ++++++++++++++++++++----- kernel/cobalt/rtdm/device.c | 24 ++++++++++++++++++++++-- kernel/cobalt/rtdm/fd.c | 13 +++++++++++-- kernel/cobalt/rtdm/internal.h | 6 ++++++ 7 files changed, 63 insertions(+), 10 deletions(-)include/cobalt/kernel/list.h +1
-1@@ -45,7 +45,7 @@ do { \ ({ \__type *__item; \ __item =list_first_entry (__head, __type, __member); \ -list_del (&__item->__member); \ +list_del (&(__item)->__member); \ __item; \ })include/cobalt/kernel/rtdm/driver.h +1
-0@@ -385,6 +385,7 @@ struct rtdm_device {atomic_t refcount;struct rtdm_fd_ops ops;wait_queue_head_t putwq; +struct list_head openfd_list; }; };include/cobalt/kernel/rtdm/fd.h +2
-0@@ -304,7 +304,9 @@ struct rtdm_fd {#ifdef CONFIG_XENO_ARCH_SYS3264 int compat;#endif +bool stale;struct list_head cleanup; +struct list_head next;/* in dev->openfd_list */ };#define RTDM_FD_MAGIC 0x52544446kernel/cobalt/rtdm/core.c +20
-5@@ -54,7 +54,7 @@ void __rtdm_dev_close(struct rtdm_fd *fd)struct rtdm_device *dev = context->device;struct rtdm_driver *drv = dev->driver; -if (drv->ops.close) +if (!fd->stale && drv->ops.close) drv->ops.close (fd);cleanup_instance (dev, context);@@ -131,6 +131,23 @@ open_devnode(struct rtdm_device *dev, const char *path, int oflag)#endif /* !CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE */ +static int register_new_fd (struct rtdm_dev_context *context,int ufd) +{ +int ret; +spl_t s; + +trace_cobalt_fd_created (&context->fd, ufd); + ret =rtdm_fd_register (&context->fd, ufd); +if (ret <0 ) +return ret; + +xnlock_get_irqsave (&nklock, s); +list_add (&context->fd.next, &context->device->openfd_list); +xnlock_put_irqrestore (&nklock, s); + +return ret; +} +int __rtdm_dev_open (const char *path,int oflag) {struct rtdm_dev_context *context;@@ -185,8 +202,7 @@ int __rtdm_dev_open(const char *path, int oflag) goto fail_open; } -trace_cobalt_fd_created (&context->fd, ufd); - ret =rtdm_fd_register (&context->fd, ufd); + ret =register_new_fd (context, ufd);if (ret <0 ) goto fail_open;@@ -240,8 +256,7 @@ int __rtdm_dev_socket(int protocol_family, int socket_type, goto fail_socket; } -trace_cobalt_fd_created (&context->fd, ufd); - ret =rtdm_fd_register (&context->fd, ufd); + ret =register_new_fd (context, ufd);if (ret <0 ) goto fail_socket;kernel/cobalt/rtdm/device.c +22
-2@@ -417,6 +417,7 @@ int rtdm_dev_register(struct rtdm_device *dev)else dev->ops.open = (typeof(dev->ops.open))enosys; +INIT_LIST_HEAD (&dev->openfd_list);init_waitqueue_head (&dev->putwq); dev->ops.close = __rtdm_dev_close;/* Interpose on driver's handler. */ atomic_set (&dev->refcount,0 );@@ -524,8 +525,9 @@ EXPORT_SYMBOL_GPL(rtdm_dev_register);/** * @brief Unregister a RTDM device * -* Removes the device from the RTDM namespace. This routine waits until -* all connections to @a device have been closed prior to unregistering. +* Removes the device from the RTDM namespace. This routine first +* attempts to teardown all active connections to the @a device prior +* to unregistering. * * @param[in] dev Device descriptor. * @@ -534,6 +536,8 @@ EXPORT_SYMBOL_GPL(rtdm_dev_register);void rtdm_dev_unregister (struct rtdm_device *dev) {struct rtdm_driver *drv = dev->driver; +struct rtdm_fd *fd; +spl_t s;secondary_mode_only ();@@ -542,6 +546,22 @@ void rtdm_dev_unregister(struct rtdm_device *dev)/* Lock out any further connection. */ dev->magic = ~RTDM_DEVICE_MAGIC ; +xnlock_get_irqsave (&nklock, s); +for (;;) { + fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next); +if (fd ==NULL ) +break ; + fd->stale = true; +if (drv->ops.close) { +rtdm_fd_get_light (fd); +xnlock_put_irqrestore (&nklock, s); + drv->ops.close (fd); +rtdm_fd_put (fd); +xnlock_get_irqsave (&nklock, s); + } + } +xnlock_put_irqrestore (&nklock, s); +/* Then wait for the ongoing connections to finish. */ wait_event (dev->putwq,atomic_read (&dev->refcount) ==0 );kernel/cobalt/rtdm/fd.c +11
-2@@ -168,7 +168,9 @@ int rtdm_fd_enter(struct rtdm_fd *fd, int ufd, unsigned int magic, fd->owner = ppd; fd->ufd = ufd; fd->refs =1 ; + fd->stale = false;set_compat_bit (fd); +INIT_LIST_HEAD (&fd->next);return 0 ; }@@ -231,6 +233,11 @@ struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic) goto out; } +if (fd->stale) { + fd =ERR_PTR (-EBADF ); + goto out; + } + ++fd->refs; out:xnlock_put_irqrestore (&fdtree_lock, s);@@ -279,7 +286,11 @@ static void __put_fd(struct rtdm_fd *fd, spl_t s) {int destroy; +XENO_WARN_ON (COBALT , fd->refs <=0 ); destroy = --fd->refs ==0 ; +if (destroy && !list_empty (&fd->next)) +list_del (&fd->next); +xnlock_put_irqrestore (&fdtree_lock, s);if (!destroy)@@ -367,8 +378,6 @@ void rtdm_fd_unlock(struct rtdm_fd *fd)spl_t s;xnlock_get_irqsave (&fdtree_lock, s); -/* Warn if fd was unreferenced. */ -XENO_WARN_ON (COBALT , fd->refs <=0 );__put_fd (fd, s); }EXPORT_SYMBOL_GPL (rtdm_fd_unlock);kernel/cobalt/rtdm/internal.h +0
-0@@ -49,6 +49,12 @@ int __rtdm_dev_ioctl_core(struct rtdm_fd *fd,int __rtdm_mmap_from_fdop (struct rtdm_fd *fd,size_t len,off_t offset,int prot,int flags,void **pptr);
kernel/cobalt/rtdm/internal.h int __rtdm_dev_ioctl_core(struct rtdm_fd *fd, · line 60
Quoted 10 lines
kernel/cobalt/rtdm/internal.h +6
-0+/* nklock held, irqs off. */ +static inline void rtdm_fd_get_light (struct rtdm_fd *fd) +{ + ++fd->refs; +} +int rtdm_init (void );void rtdm_cleanup (void );
Hi Philippe,
I tested xenomai-next with xeno-test on 4.19.66+ amd64.
This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Kind regards,
Quirin
-------------- next part --------------
2019-09-04T13:25:46 + lava-test-case xenomai-test --shell xeno-test -k -l \"dohell -m /tmp 300\" -p 1000 2019-09-04T13:25:46 Received signal: <STARTTC> xenomai-test 2019-09-04T13:25:46 <LAVA_SIGNAL_STARTTC xenomai-test> 2019-09-04T13:25:46 Started child 269: /bin/sh /usr/lib/xenomai/testsuite/xeno-test-run-wrapper /usr/bin/xeno-test -k -p 1000 2019-09-04T13:25:46 + echo 0 2019-09-04T13:25:46 + testdir=/usr/lib/xenomai/testsuite 2019-09-04T13:25:46 + /usr/lib/xenomai/testsuite/smokey --run --keep-going random_alloc_rounds=64 pattern_check_rounds=64 2019-09-04T13:25:46 arith OK 2019-09-04T13:25:49 bufp OK 2019-09-04T13:25:49 cpu_affinity skipped (no kernel support) 2019-09-04T13:25:49 fpu_stress OK 2019-09-04T13:25:50 gdb OK 2019-09-04T13:25:53 iddp OK 2019-09-04T13:25:55 leaks OK 2019-09-04T13:26:53 memory_coreheap OK 2019-09-04T13:27:04 memory_heapmem OK 2019-09-04T13:27:11 memory_tlsf OK 2019-09-04T13:27:11 net_packet_dgram skipped (no kernel support) 2019-09-04T13:27:11 net_packet_raw skipped (no kernel support) 2019-09-04T13:27:11 net_udp skipped (no kernel support) 2019-09-04T13:27:31 posix_clock OK 2019-09-04T13:27:31 posix_cond OK 2019-09-04T13:27:31 posix_fork OK 2019-09-04T13:27:31 posix_mutex OK 2019-09-04T13:27:36 posix_select OK 2019-09-04T13:27:37 [ 226.145583] general protection fault: 0000 [#1] PREEMPT SMP PTI 2019-09-04T13:27:37 [ 226.152028] CPU: 0 PID: 326 Comm: rmmod Tainted: G W 4.19.66+ #1 2019-09-04T13:27:37 [ 226.159974] Hardware name: LENOVO 10SRS0N900/312A, BIOS M1UKT23A 12/05/2018 2019-09-04T13:27:37 [ 226.167537] I-pipe domain: Linux 2019-09-04T13:27:37 [ 226.171056] RIP: 0010:__list_del_entry_valid+0x0/0x90 2019-09-04T13:27:37 [ 226.176546] Code: 0a 82 e8 6f be b9 ff 0f 0b 31 c0 c3 48 89 f2 4c 89 c1 48 89 fe 48 c7 c7 90 ff 0a 82 e8 55 be b9 ff 0f 0b 31 c0 c3 0f 1f 40 00 <48> 8b 07 48 8b 57 08 48 b9 00 01 00 00 00 00 ad de 48 39 c8 74 26 2019-09-04T13:27:37 [ 226.196929] RSP: 0018:ffffc900015cfe60 EFLAGS: 00010212 2019-09-04T13:27:37 [ 226.202619] RAX: 0000000015777bd0 RBX: dead0000000000c0 RCX: ffffffff82084b0a 2019-09-04T13:27:37 [ 226.210364] RDX: 0000000000000034 RSI: 0000000000000000 RDI: dead000000000100 2019-09-04T13:27:37 [ 226.218095] RBP: ffffffffa0002000 R08: 0000000000000230 R09: ffffffff81e239e0 2019-09-04T13:27:37 [ 226.225846] R10: 000000c415777b9c R11: ffffffff8370389c R12: ffffffffa0002760 2019-09-04T13:27:37 [ 226.233594] R13: dead000000000200 R14: dead000000000100 R15: dead000000000100 2019-09-04T13:27:37 [ 226.241350] FS: 00007fd67732e200(0000) GS:ffff888159c00000(0000) knlGS:0000000000000000 2019-09-04T13:27:37 [ 226.250137] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 2019-09-04T13:27:37 [ 226.256379] CR2: 00007fd677390c20 CR3: 00000001500f0001 CR4: 00000000003606f0 2019-09-04T13:27:37 [ 226.264122] Call Trace: 2019-09-04T13:27:37 [ 226.266796] rtdm_dev_unregister+0x150/0x5c0 2019-09-04T13:27:37 [ 226.271448] ? __mutex_unlock_slowpath+0x4b/0x2b0 2019-09-04T13:27:37 [ 226.276571] rtdm_test_exit+0xc/0xa6c [xeno_rtdmtest] 2019-09-04T13:27:37 [ 226.282061] __x64_sys_delete_module+0x139/0x1d0 2019-09-04T13:27:37 [ 226.287087] ? do_syscall_64+0x16/0x3a0 2019-09-04T13:27:37 [ 226.291263] do_syscall_64+0x77/0x3a0 2019-09-04T13:27:37 [ 226.295244] entry_SYSCALL_64_after_hwframe+0x49/0xbe 2019-09-04T13:27:37 [ 226.300720] RIP: 0033:0x7fd67744edd7 2019-09-04T13:27:37 [ 226.304601] Code: 73 01 c3 48 8b 0d b9 10 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 b0 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 89 10 0c 00 f7 d8 64 89 01 48 2019-09-04T13:27:37 [ 226.324948] RSP: 002b:00007ffcb20c2368 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0 2019-09-04T13:27:37 [ 226.333173] RAX: ffffffffffffffda RBX: 0000558e7f19d750 RCX: 00007fd67744edd7 2019-09-04T13:27:37 [ 226.340927] RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000558e7f19d7b8 2019-09-04T13:27:37 [ 226.348672] RBP: 0000000000000000 R08: 00007ffcb20c12e1 R09: 0000000000000000 2019-09-04T13:27:37 [ 226.356418] R10: 00007fd6774c0ae0 R11: 0000000000000206 R12: 00007ffcb20c2590 2019-09-04T13:27:37 [ 226.364166] R13: 00007ffcb20c3def R14: 0000558e7f19d260 R15: 0000558e7f19d750 2019-09-04T13:27:37 [ 226.371923] Modules linked in: xeno_rtdmtest(-) 2019-09-04T13:27:37 [ 226.376866] ---[ end trace 09d7b0b2bc47651a ]--- 2019-09-04T13:27:37 [ 226.528377] RIP: 0010:__list_del_entry_valid+0x0/0x90 2019-09-04T13:27:37 [ 226.533841] Code: 0a 82 e8 6f be b9 ff 0f 0b 31 c0 c3 48 89 f2 4c 89 c1 48 89 fe 48 c7 c7 90 ff 0a 82 e8 55 be b9 ff 0f 0b 31 c0 c3 0f 1f 40 00 <48> 8b 07 48 8b 57 08 48 b9 00 01 00 00 00 00 ad de 48 39 c8 74 26 2019-09-04T13:27:37 [ 226.554118] RSP: 0018:ffffc900015cfe60 EFLAGS: 00010212 2019-09-04T13:27:37 [ 226.559778] RAX: 0000000015777bd0 RBX: dead0000000000c0 RCX: ffffffff82084b0a 2019-09-04T13:27:37 [ 226.567495] RDX: 0000000000000034 RSI: 0000000000000000 RDI: dead000000000100 2019-09-04T13:27:37 [ 226.575215] RBP: ffffffffa0002000 R08: 0000000000000230 R09: ffffffff81e239e0 2019-09-04T13:27:37 [ 226.582934] R10: 000000c415777b9c R11: ffffffff8370389c R12: ffffffffa0002760 2019-09-04T13:27:37 [ 226.590662] R13: dead000000000200 R14: dead000000000100 R15: dead000000000100 2019-09-04T13:27:37 [ 226.598382] FS: 00007fd67732e200(0000) GS:ffff888159c00000(0000) knlGS:0000000000000000 2019-09-04T13:27:37 [ 226.607130] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 2019-09-04T13:27:37 [ 226.613359] CR2: 00007fd677390c20 CR3: 00000001500f0001 CR4: 00000000003606f0 2019-09-04T13:27:37 [ 226.621074] BUG: sleeping function called from invalid context at include/linux/percpu-rwsem.h:34 2019-09-04T13:27:37 [ 226.630656] in_atomic(): 0, irqs_disabled(): 1, pid: 326, name: rmmod 2019-09-04T13:27:37 [ 226.637634] INFO: lockdep is turned off. 2019-09-04T13:27:37 [ 226.641890] irq event stamp: 4320 2019-09-04T13:27:37 [ 226.645486] hardirqs last enabled at (4319): [<ffffffff819a3991>] restore_local_irqs+0x2c/0x36 2019-09-04T13:27:37 [ 226.654903] hardirqs last disabled at (4320): [<ffffffff810ac48e>] __ipipe_trap_prologue+0x11e/0x300 2019-09-04T13:27:37 [ 226.664764] softirqs last enabled at (3958): [<ffffffff819736fb>] rpc_wake_up_first_on_wq+0x7b/0x1d0 2019-09-04T13:27:37 [ 226.674745] softirqs last disabled at (3956): [<ffffffff819736a7>] rpc_wake_up_first_on_wq+0x27/0x1d0 2019-09-04T13:27:37 [ 226.684718] CPU: 0 PID: 326 Comm: rmmod Tainted: G D W 4.19.66+ #1 2019-09-04T13:27:37 [ 226.692619] Hardware name: LENOVO 10SRS0N900/312A, BIOS M1UKT23A 12/05/2018 2019-09-04T13:27:37 [ 226.700147] I-pipe domain: Linux 2019-09-04T13:27:37 [ 226.703645] Call Trace: 2019-09-04T13:27:37 [ 226.706312] dump_stack+0x74/0x9a 2019-09-04T13:27:37 [ 226.709907] ? wake_up_klogd+0x10/0x70 2019-09-04T13:27:37 [ 226.713973] ___might_sleep.cold.81+0x108/0x120 2019-09-04T13:27:37 [ 226.718888] exit_signals+0x30/0x2a0 2019-09-04T13:27:37 [ 226.722765] do_exit+0xbc/0xc30 2019-09-04T13:27:37 [ 226.726178] ? do_syscall_64+0x16/0x3a0 2019-09-04T13:27:37 [ 226.730344] rewind_stack_do_exit+0x17/0x20 2019-09-04T13:27:37 [ 226.735115] WARNING: CPU: 0 PID: 326 at kernel/ipipe/core.c:1837 __ipipe_spin_unlock_debug+0x14/0x20 2019-09-04T13:27:37 [ 226.744794] Modules linked in: xeno_rtdmtest(-) 2019-09-04T13:27:37 [ 226.749799] CPU: 0 PID: 326 Comm: rmmod Tainted: G D W 4.19.66+ #1 2019-09-04T13:27:37 [ 226.757858] Hardware name: LENOVO 10SRS0N900/312A, BIOS M1UKT23A 12/05/2018 2019-09-04T13:27:37 [ 226.765546] I-pipe domain: Linux 2019-09-04T13:27:37 [ 226.768982] RIP: 0010:__ipipe_spin_unlock_debug+0x14/0x20 2019-09-04T13:27:37 [ 226.774717] Code: 99 d9 07 82 e8 0d b0 f7 ff 48 89 df 5b e9 a4 40 ed ff 0f 1f 40 00 e8 9b 9b 82 00 f7 c7 00 02 00 00 74 09 9c 58 f6 c4 02 75 02 <0f> 0b c3 66 0f 1f 84 00 00 00 00 00 e8 7b 9b 82 00 53 b8 ff ff ff 2019-09-04T13:27:37 [ 226.795289] RSP: 0018:ffffc900015cfdb8 EFLAGS: 00010046 2019-09-04T13:27:37 [ 226.800991] RAX: 0000000000000006 RBX: 000000000000000b RCX: 0000000000000002 2019-09-04T13:27:37 [ 226.808803] RDX: ffff88815e7f9000 RSI: 000000000000000b RDI: 0000000000000200 2019-09-04T13:27:37 [ 226.816374] RBP: ffff888159eb95e0 R08: ffffea00053bf5c8 R09: 0000000000000001 2019-09-04T13:27:37 [ 226.823946] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000200 2019-09-04T13:27:37 [ 226.831821] R13: ffffffff8129b450 R14: ffff88815e7f9000 R15: ffffea00053ca000 2019-09-04T13:27:37 [ 226.839393] FS: 0000000000000000(0000) GS:ffff888159c00000(0000) knlGS:0000000000000000 2019-09-04T13:27:37 [ 226.848235] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 2019-09-04T13:27:37 [ 226.854553] CR2: 00007fd677390c20 CR3: 000000000221e005 CR4: 00000000003606f0 2019-09-04T13:27:37 [ 226.862126] Call Trace: 2019-09-04T13:27:37 [ 226.864807] pagevec_lru_move_fn+0xaf/0xf0 2019-09-04T13:27:37 [ 226.869175] lru_add_drain_cpu+0x7c/0x170 2019-09-04T13:27:37 [ 226.873442] lru_add_drain+0x1b/0x40 2019-09-04T13:27:37 [ 226.877243] exit_mmap+0x76/0x170 2019-09-04T13:27:37 [ 226.880780] ? ipipe_kevent_hook+0x8b7/0xde4 2019-09-04T13:27:37 [ 226.885509] mmput+0x6d/0x130 2019-09-04T13:27:37 [ 226.888673] do_exit+0x3ad/0xc30 2019-09-04T13:27:37 [ 226.892121] ? do_syscall_64+0x16/0x3a0 2019-09-04T13:27:37 [ 226.896216] rewind_stack_do_exit+0x17/0x20 2019-09-04T13:27:37 [ 226.900693] irq event stamp: 4320 2019-09-04T13:27:37 [ 226.904224] hardirqs last enabled at (4319): [<ffffffff819a3991>] restore_local_irqs+0x2c/0x36 2019-09-04T13:27:37 [ 226.913823] hardirqs last disabled at (4320): [<ffffffff810ac48e>] __ipipe_trap_prologue+0x11e/0x300 2019-09-04T13:27:37 [ 226.923770] softirqs last enabled at (3958): [<ffffffff819736fb>] rpc_wake_up_first_on_wq+0x7b/0x1d0 2019-09-04T13:27:37 [ 226.933874] softirqs last disabled at (3956): [<ffffffff819736a7>] rpc_wake_up_first_on_wq+0x27/0x1d0 2019-09-04T13:27:37 [ 226.943657] ---[ end trace 09d7b0b2bc47651b ]---
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Signature · 1 line
Philippe.
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Quoted 9 lines
Quoted 2 lines
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.
The issue is that a wrong pointer is passed to the driver close call.
Signature · 1 line
Philippe.
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Quoted 7 lines
Quoted 2 lines
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.
Can you elaborate on the execution scenario that would allow this?
Signature · 1 line
Philippe.
Quoted 11 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 6 lines
Quoted 4 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.Can you elaborate on the execution scenario that would allow this?
Both the fd_cleanup_thread as well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 17 lines · Jan Kiszka via Xenomai
Quoted 16 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.
Quoted 6 lines
Quoted 1 line
Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.
This should do that trick, btw:
kernel/cobalt/rtdm/device.c +2 -0
@@ -554,6 +554,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev) fd->stale = true;if (drv->ops.close) {rtdm_fd_get_light (fd); +if (!list_empty (&fd->cleanup)) +list_del (&fd->cleanup);xnlock_put_irqrestore (&nklock, s); drv->ops.close (fd);rtdm_fd_put (fd);
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.
Quoted 6 lines
Quoted 1 line
Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.
I mean, given the maintenance logic between openfd_list and the cleanup_fd_list, which condition can make this possible?
Signature · 1 line
Philippe.
Quoted 20 lines · Philippe Gerum via Xenomai
Quoted 19 lines · Jan Kiszka
Quoted 17 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Quoted 7 lines
Quoted 2 lines
Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.Can you elaborate on the execution scenario that would allow this?
Quoted 9 lines
Quoted 4 lines
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.I mean, given the maintenance logic between
openfd_listand thecleanup_fd_list, which condition can make this possible?
The answer may involve __put_fd() serializing on fdtree_lock, whilst rtdm_dev_unregister() serializes on the ugly big nklock.
Signature · 1 line
Philippe.
Quoted 26 lines · Philippe Gerum via Xenomai
Quoted 25 lines · Philippe Gerum via Xenomai
Quoted 23 lines · Jan Kiszka
Quoted 11 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 6 lines
Quoted 4 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.
Quoted 8 lines
Quoted 4 lines
I mean, given the maintenance logic between
openfd_listand thecleanup_fd_list, which condition can make this possible?The answer may involve
__put_fd()serializing onfdtree_lock, whilstrtdm_dev_unregister()serializes on the ugly big nklock.
The whole thing needs cleanup, I follow up on this.
Signature · 1 line
Philippe.
Quoted 26 lines · Philippe Gerum
Quoted 25 lines · Philippe Gerum via Xenomai
Quoted 23 lines · Jan Kiszka
Quoted 11 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 6 lines
Quoted 4 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue.Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.
Quoted 8 lines
Quoted 4 lines
I mean, given the maintenance logic between
openfd_listand thecleanup_fd_list, which condition can make this possible?The answer may involve
__put_fd()serializing onfdtree_lock, whilstrtdm_dev_unregister()serializes on the ugly big nklock.
Indeed, unregister will not pick up anything that is in the cleanup queue. But what ensures that unregisters waits for fd_cleanup_thread to finish first?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Philippe Gerum
Quoted 33 lines · Philippe Gerum via Xenomai
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Philippe Gerum
Quoted 17 lines · Jan Kiszka
Quoted 9 lines · Philippe Gerum via Xenomai
Quoted 6 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of
xeno-test. The log is attached.Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple
times. One thing I already found out: It's not a good idea to close the
fd on unregister without also ensuring that it's no longer pending inrtdm_fd_cleanup_queue.Quoted 7 lines
Quoted 1 line
Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run
concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.I mean, given the maintenance logic between
openfd_listand thecleanup_fd_list, which condition can make this possible?
Quoted 8 lines
Quoted 3 lines
The answer may involve
__put_fd()serializing onfdtree_lock, whilstrtdm_dev_unregister()serializes on the ugly big nklock.Indeed, unregister will not pick up anything that is in the cleanup queue. But what ensures that unregisters waits for
fd_cleanup_threadto finish first?
__rtdm_dev_close() is interposed on ->close handling for every non-core file descriptor (i.e. anything but timerfd and mqs), and that one holds the last reference in dev->refcount. So until the cleanup thread eventually calls __rtdm_dev_close() via ops->close(), rtdm_dev_unregister() should sleep on putwq.
Signature · 1 line
Philippe.
Quoted 46 lines · Philippe Gerum
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Philippe Gerum
Quoted 33 lines · Philippe Gerum via Xenomai
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Philippe Gerum
Quoted 17 lines · Jan Kiszka
Quoted 9 lines · Philippe Gerum via Xenomai
Quoted 6 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of
xeno-test. The log is attached.Ok, I'll have a look. Thanks.
I've started to dig into this a bit already but got distracted multiple
times. One thing I already found out: It's not a good idea to close the
fd on unregister without also ensuring that it's no longer pending inrtdm_fd_cleanup_queue.Quoted 7 lines
Quoted 1 line
Can you elaborate on the execution scenario that would allow this?
Both the
fd_cleanup_threadas well as rmmod are Linux tasks that can run
concurrently on separate cores. It might be unlikely, but it is possible, nothing prevents this from happening.I mean, given the maintenance logic between
openfd_listand thecleanup_fd_list, which condition can make this possible?Quoted 8 lines
Quoted 3 lines
The answer may involve
__put_fd()serializing onfdtree_lock, whilstrtdm_dev_unregister()serializes on the ugly big nklock.Indeed, unregister will not pick up anything that is in the cleanup queue. But what ensures that unregisters waits for
fd_cleanup_threadto finish first?
Quoted 6 lines
__rtdm_dev_close()is interposed on ->close handling for every non-core file descriptor (i.e. anything but timerfd and mqs), and that one holds the last reference indev->refcount. So until the cleanup thread eventually calls__rtdm_dev_close()viaops->close(),rtdm_dev_unregister()should sleep on putwq.
OK, that sounds good.
BTW, there is some room for cleanups around nop_close and default handlers. Will send patches.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 8 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.Jan
There is that stupid bug at least:
kernel/cobalt/rtdm/device.c +2 -0
@@ -548,6 +548,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev)xnlock_get_irqsave (&nklock, s);for (;;) { +if (list_empty (&dev->openfd_list)) +break ; fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next);if (fd ==NULL )break ;
Signature · 1 line
Philippe.
Quoted 28 lines · Philippe Gerum via Xenomai
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 8 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.Jan
There is that stupid bug at least:
kernel/cobalt/rtdm/device.c +0
-0
kernel/cobalt/rtdm/device.c void rtdm_dev_unregister(struct rtdm_device *dev) · line 555
Quoted 8 lines
kernel/cobalt/rtdm/device.c +2
-0@@ -548,6 +548,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev)xnlock_get_irqsave (&nklock, s);for (;;) { +if (list_empty (&dev->openfd_list)) +break ; fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next);if (fd ==NULL )break ;
a second one involves a double release of an rtdm_fd from the openfd_list.
Signature · 1 line
Philippe.
Quoted 29 lines · Philippe Gerum via Xenomai
Quoted 28 lines · Philippe Gerum via Xenomai
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 8 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.Jan
There is that stupid bug at least:
kernel/cobalt/rtdm/device.c +0
-0@@ -548,6 +548,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev)
Quoted 11 lines
kernel/cobalt/rtdm/device.c void rtdm_dev_unregister(struct rtdm_device *dev) · line 555
Quoted 8 lines
kernel/cobalt/rtdm/device.c +2
-0xnlock_get_irqsave (&nklock, s);for (;;) { +if (list_empty (&dev->openfd_list)) +break ; fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next);if (fd ==NULL )break ;a second one involves a double release of an
rtdm_fdfrom theopenfd_list.
not a double release in fact, but some fd lingers preventing the unregister to complete. So reference count issue likely.
Signature · 1 line
Philippe.
Quoted 28 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 8 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.Jan
There is that stupid bug at least:
kernel/cobalt/rtdm/device.c +0
-0
kernel/cobalt/rtdm/device.c void rtdm_dev_unregister(struct rtdm_device *dev) · line 555
Quoted 8 lines
kernel/cobalt/rtdm/device.c +2
-0@@ -548,6 +548,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev)xnlock_get_irqsave (&nklock, s);for (;;) { +if (list_empty (&dev->openfd_list)) +break ; fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next);if (fd ==NULL )break ;
Then you can also drop that NULL check - list_get_entry never returns NULL.
I'll remove the commit from next so that you can send a v5.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 39 lines · Jan Kiszka
Quoted 27 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum via Xenomai
Quoted 5 lines · Quirin Gylstorff via Xenomai
I tested xenomai-next with xeno-test on 4.19.66+ amd64. This patch triggers a general protection fault during the execution of xeno-test. The log is attached.
Ok, I'll have a look. Thanks.
Quoted 8 lines
I've started to dig into this a bit already but got distracted multiple times. One thing I already found out: It's not a good idea to close the fd on unregister without also ensuring that it's no longer pending in
rtdm_fd_cleanup_queue. But fixing that does not resolve the issue we see with the test case.Jan
There is that stupid bug at least:
kernel/cobalt/rtdm/device.c +0
-0kernel/cobalt/rtdm/device.c void rtdm_dev_unregister(struct rtdm_device *dev) · line 555
Quoted 8 lines
kernel/cobalt/rtdm/device.c +2
-0@@ -548,6 +548,8 @@ void rtdm_dev_unregister(struct rtdm_device *dev) xnlock_get_irqsave(&nklock, s); for (;;) { + if (list_empty(&dev->openfd_list)) + break; fd = list_get_entry(&dev->openfd_list, struct rtdm_fd, next); if (fd == NULL) break;Then you can also drop that NULL check -
list_get_entrynever returns NULL.
Quoted 2 lines
I'll remove the commit from next so that you can send a v5.
This is only material for discussion illustrating a point, please do not merge any of those snippets.
Signature · 1 line
Philippe.