RTnet reformatting in next
Hi all, just a heads-up that I pushed this to next: kernel/drivers/net/addons/cap.c| 680 +++-- kernel/drivers/net/addons/proxy.c | 373 ++- .../net/drivers/experimental/rt2500/rt2500pci.c| 1798 ++-- .../net/drivers/experimental/rt2500/rt2500pci.h| 1762 ++-- .../net/drivers/experimental/rt2500/rt2x00.h | 677 ++--- .../net/drivers/experimental/rt2500/rt2x00core.c | 565 ++-- kernel/drivers/net/drivers/loopback.c | 93 +- kernel/drivers/net/drivers/pcnet32.c | 2020 +++--- kernel/drivers/net/stack/corectl.c |4 +- kernel/drivers/net/stack/eth.c | 106 +- kernel/drivers/net/stack/include/ethernet/eth.h| 12 +- kernel/drivers/net/stack/include/ipv4/af_inet.h|3 +- kernel/drivers/net/stack/include/ipv4/arp.h| 19 +- kernel/drivers/net/stack/include/ipv4/icmp.h | 18 +- .../drivers/net/stack/include/ipv4/ip_fragment.h |6 +- kernel/drivers/net/stack/include/ipv4/ip_input.h |4 +- kernel/drivers/net/stack/include/ipv4/ip_output.h | 10 +- kernel/drivers/net/stack/include/ipv4/ip_sock.h|3 +- kernel/drivers/net/stack/include/ipv4/protocol.h | 20 +- kernel/drivers/net/stack/include/ipv4/route.h | 16 +- kernel/drivers/net/stack/include/ipv4/tcp.h| 18 +- kernel/drivers/net/stack/include/ipv4/udp.h|4 +- kernel/drivers/net/stack/include/ipv4_chrdev.h | 116 +- kernel/drivers/net/stack/include/nomac_chrdev.h| 12 +- kernel/drivers/net/stack/include/rtcfg/rtcfg.h |4 +- .../net/stack/include/rtcfg/rtcfg_client_event.h | 15 +- .../net/stack/include/rtcfg/rtcfg_conn_event.h | 34 +- .../drivers/net/stack/include/rtcfg/rtcfg_event.h | 113 +- .../drivers/net/stack/include/rtcfg/rtcfg_file.h | 12 +- .../drivers/net/stack/include/rtcfg/rtcfg_frame.h | 112 +- .../drivers/net/stack/include/rtcfg/rtcfg_ioctl.h |5 +- .../drivers/net/stack/include/rtcfg/rtcfg_proc.h | 18 +- kernel/drivers/net/stack/include/rtcfg_chrdev.h| 263 +- kernel/drivers/net/stack/include/rtdev.h | 228 +- kernel/drivers/net/stack/include/rtdev_mgr.h | 18 +- kernel/drivers/net/stack/include/rtmac.h | 46 +- .../drivers/net/stack/include/rtmac/nomac/nomac.h | 23 +- .../net/stack/include/rtmac/nomac/nomac_dev.h |4 +- .../net/stack/include/rtmac/nomac/nomac_ioctl.h|3 +- .../net/stack/include/rtmac/nomac/nomac_proto.h|1 - .../drivers/net/stack/include/rtmac/rtmac_disc.h | 60 +- .../drivers/net/stack/include/rtmac/rtmac_proc.h |2 - .../drivers/net/stack/include/rtmac/rtmac_proto.h | 61 +- .../drivers/net/stack/include/rtmac/rtmac_vnic.h |8 +- kernel/drivers/net/stack/include/rtmac/tdma/tdma.h | 171 +- .../net/stack/include/rtmac/tdma/tdma_dev.h|4 +- .../net/stack/include/rtmac/tdma/tdma_ioctl.h |3 +- .../net/stack/include/rtmac/tdma/tdma_proto.h | 50 +- .../net/stack/include/rtmac/tdma/tdma_worker.h |3 +- kernel/drivers/net/stack/include/rtnet_chrdev.h| 113 +- kernel/drivers/net/stack/include/rtnet_internal.h | 27 +- kernel/drivers/net/stack/include/rtnet_iovec.h | 10 +- kernel/drivers/net/stack/include/rtnet_port.h | 33 +- kernel/drivers/net/stack/include/rtnet_rtpc.h | 46 +- kernel/drivers/net/stack/include/rtnet_socket.h| 84 +- kernel/drivers/net/stack/include/rtskb.h | 555 ++-- kernel/drivers/net/stack/include/rtskb_fifo.h | 133 +- kernel/drivers/net/stack/include/rtwlan.h | 265 +- kernel/drivers/net/stack/include/rtwlan_io.h | 122 +- kernel/drivers/net/stack/include/stack_mgr.h | 35 +- kernel/drivers/net/stack/include/tdma_chrdev.h | 83 +- kernel/drivers/net/stack/iovec.c | 13 +- kernel/drivers/net/stack/ipv4/af_inet.c| 375 ++- kernel/drivers/net/stack/ipv4/arp.c| 232 +- kernel/drivers/net/stack/ipv4/icmp.c | 612 ++--- kernel/drivers/net/stack/ipv4/ip_fragment.c| 407 ++- kernel/drivers/net/stack/ipv4/ip_input.c | 156 +- kernel/drivers/net/stack/ipv4/ip_output.c | 377 ++- kernel/drivers/net/stack/ipv4/ip_sock.c| 227 +- kernel/drivers/net/stack/ipv4/protocol.c | 61 +- kernel/drivers/net/stack/ipv4/route.c | 1160 kernel/drivers/net/stack/ipv4/tcp/tcp.c| 2871 ++-- kernel/drivers/net/stack/ipv4/tcp/timerwheel.c | 229 +- kernel/drivers/net/stack/ipv4/tcp/timerwheel.h | 31 +- kernel/drivers/net/stack/ipv4/udp/udp.c| 984 --- kernel/drivers/net/stack/packet/af_packet.c| 732 +++-- .../drivers/net/stack/rtcfg/rtcfg_client_event.c | 1964 +++-- kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c | 514 ++--
[PATCH] ci: Update x86 ipipe releases
From: Jan Kiszka Signed-off-by: Jan Kiszka --- .travis.yml | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3453b0ff9..da7380cd10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -164,7 +164,7 @@ matrix: KERNEL_DEFCONFIG: multi_v7_defconfig - env: - ARCH: arm -IPIPE_REV: ipipe-4.4.y +IPIPE_REV: ipipe-4.4.y-cip IPIPE_KERNEL: https://gitlab.denx.de/Xenomai/ipipe.git KERNEL_DEFCONFIG: multi_v7_defconfig - env: @@ -179,7 +179,7 @@ matrix: KERNEL_DEFCONFIG: x86_64_defconfig - env: - ARCH: x86 -IPIPE_REV: ipipe-core-4.19.56-x86-2 +IPIPE_REV: ipipe-core-4.19.66-x86-6 IPIPE_KERNEL: https://gitlab.denx.de/Xenomai/ipipe-x86.git KERNEL_DEFCONFIG: x86_64_defconfig - env: @@ -189,12 +189,12 @@ matrix: KERNEL_DEFCONFIG: x86_64_defconfig - env: - ARCH: x86 -IPIPE_REV: ipipe-4.4.y +IPIPE_REV: ipipe-4.4.y-cip IPIPE_KERNEL: https://gitlab.denx.de/Xenomai/ipipe.git KERNEL_DEFCONFIG: x86_64_defconfig - env: - ARCH: x86 -IPIPE_REV: ipipe-core-4.4.182-x86-15 +IPIPE_REV: ipipe-core-4.4.188-cip36-x86-17 IPIPE_KERNEL: https://gitlab.denx.de/Xenomai/ipipe.git KERNEL_DEFCONFIG: x86_64_defconfig - env: -- 2.16.4 -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH v4 2/2] cobalt/rtdm: allow for device teardown
On 30.08.19 19:16, Philippe Gerum wrote: On 8/30/19 6:58 PM, Jan Kiszka wrote: On 30.08.19 18:03, Philippe Gerum wrote: Currently, rtdm_dev_unregister() will hang soft until all references on the dismantled device have been dropped, which in turn cannot happen until all rtdm_fds on 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 prevents rtdm_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 from rtdm_dev_unregister(). Since a close() 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 --- 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(-) diff --git a/include/cobalt/kernel/list.h b/include/cobalt/kernel/list.h index 989d934b8..37b91b0d5 100644 --- a/include/cobalt/kernel/list.h +++ b/include/cobalt/kernel/list.h @@ -45,7 +45,7 @@ do { \ ({ \ __type *__item; \ __item = list_first_entry(__head, __type, __member); \ - list_del(&__item->__member); \ + list_del(&(__item)->__member); \ Not really needed, is it? Just trying to understand. No, just overlooked the declaration scope of the variable. Ok, dropped why merging. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH v4 1/2] cobalt: switch hand over status to -EADV for non-RTDM fd
On 30.08.19 19:36, Philippe Gerum wrote: On 8/30/19 7:13 PM, Philippe Gerum via Xenomai wrote: On 8/30/19 6:58 PM, Jan Kiszka wrote: On 30.08.19 18:03, Philippe Gerum wrote: Having the RTDM core return -EBADF to indicate that it does not manage a file descriptor is a problem, as several drivers also raise this error to notify userland about an aborted wait due to a connection being dismantled (e.g. RTnet). In this case, libcobalt ends up forwarding the aborted request to the glibc, which is wrong. Switch from -EBADF to -EADV to notify userland that RTDM does not manage a file descriptor, which cannot conflict with any sensible error code the Cobalt core or any RTDM driver may return. I'm seeing a few more suspicious occurrences of EBADF in the core: kernel/cobalt/posix/io.c:191: return -EBADF; kernel/cobalt/posix/io.c:289: return -EBADF; kernel/cobalt/posix/syscall32.c:742:return -EBADF; We still want to receive -EBADF on wrong fildes appearing in select() descriptors. FWIW, the rationale for this change is that forwarding a request to glibc iff the first fd found in a set is a regular one is really fragile and actually never worked properly: what if there is a mixed set of rtdm/regular fds, with the first one belonging to RTDM? So people should make sure to call libcobalt's version of select() if they want to monitor RTDM fds, __STD(select()) otherwise. Relying on a silent fallback from libcobalt to glibc solely based on fairly weak heuristics is not helping anyone in the end. Indeed. Do we have a good place for documenting this? Thanks for clarifying - merged to next now. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH v4 1/2] cobalt: switch hand over status to -EADV for non-RTDM fd
On 8/30/19 7:13 PM, Philippe Gerum via Xenomai wrote: > On 8/30/19 6:58 PM, Jan Kiszka wrote: >> On 30.08.19 18:03, Philippe Gerum wrote: >>> Having the RTDM core return -EBADF to indicate that it does not manage >>> a file descriptor is a problem, as several drivers also raise this >>> error to notify userland about an aborted wait due to a connection >>> being dismantled (e.g. RTnet). In this case, libcobalt ends up >>> forwarding the aborted request to the glibc, which is wrong. >>> >>> Switch from -EBADF to -EADV to notify userland that RTDM does not >>> manage a file descriptor, which cannot conflict with any sensible >>> error code the Cobalt core or any RTDM driver may return. >> >> I'm seeing a few more suspicious occurrences of EBADF in the core: >> >> kernel/cobalt/posix/io.c:191: return -EBADF; >> kernel/cobalt/posix/io.c:289: return -EBADF; >> kernel/cobalt/posix/syscall32.c:742:return -EBADF; > > We still want to receive -EBADF on wrong fildes appearing in select() > descriptors. FWIW, the rationale for this change is that forwarding a request to glibc iff the first fd found in a set is a regular one is really fragile and actually never worked properly: what if there is a mixed set of rtdm/regular fds, with the first one belonging to RTDM? So people should make sure to call libcobalt's version of select() if they want to monitor RTDM fds, __STD(select()) otherwise. Relying on a silent fallback from libcobalt to glibc solely based on fairly weak heuristics is not helping anyone in the end. -- Philippe.
Re: [PATCH v4 2/2] cobalt/rtdm: allow for device teardown
On 8/30/19 6:58 PM, Jan Kiszka wrote: > On 30.08.19 18:03, Philippe Gerum wrote: >> Currently, rtdm_dev_unregister() will hang soft until all references >> on the dismantled device have been dropped, which in turn cannot >> happen until all rtdm_fds on 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 prevents rtdm_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 from rtdm_dev_unregister(). >> Since a close() 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 >> --- >> 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(-) >> >> diff --git a/include/cobalt/kernel/list.h b/include/cobalt/kernel/list.h >> index 989d934b8..37b91b0d5 100644 >> --- a/include/cobalt/kernel/list.h >> +++ b/include/cobalt/kernel/list.h >> @@ -45,7 +45,7 @@ do { \ >> ({ \ >> __type *__item; \ >> __item = list_first_entry(__head, __type, __member); \ >> - list_del(&__item->__member); \ >> + list_del(&(__item)->__member); \ > > Not really needed, is it? Just trying to understand. > No, just overlooked the declaration scope of the variable. -- Philippe.
Re: [PATCH v4 1/2] cobalt: switch hand over status to -EADV for non-RTDM fd
On 8/30/19 6:58 PM, Jan Kiszka wrote: > On 30.08.19 18:03, Philippe Gerum wrote: >> Having the RTDM core return -EBADF to indicate that it does not manage >> a file descriptor is a problem, as several drivers also raise this >> error to notify userland about an aborted wait due to a connection >> being dismantled (e.g. RTnet). In this case, libcobalt ends up >> forwarding the aborted request to the glibc, which is wrong. >> >> Switch from -EBADF to -EADV to notify userland that RTDM does not >> manage a file descriptor, which cannot conflict with any sensible >> error code the Cobalt core or any RTDM driver may return. >> >> Signed-off-by: Philippe Gerum >> --- >> kernel/cobalt/rtdm/core.c | 4 ++-- >> kernel/cobalt/rtdm/fd.c | 36 + >> lib/cobalt/rtdm.c | 48 +++ >> 3 files changed, 47 insertions(+), 41 deletions(-) >> >> diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c >> index c1aedb3d0..28db7adb7 100644 >> --- a/kernel/cobalt/rtdm/core.c >> +++ b/kernel/cobalt/rtdm/core.c >> @@ -154,7 +154,7 @@ int __rtdm_dev_open(const char *path, int oflag) >> */ >> dev = __rtdm_get_namedev(path); >> if (dev == NULL) >> -return -ENODEV; >> +return -EADV; >> >> ufd = get_unused_fd_flags(oflag); >> if (ufd < 0) { >> @@ -266,7 +266,7 @@ int __rtdm_dev_ioctl_core(struct rtdm_fd *fd, unsigned >> int request, >> struct rtdm_device_info dev_info; >> >> if (fd->magic != RTDM_FD_MAGIC || request != RTIOC_DEVICE_INFO) >> -return -ENOSYS; >> +return -EADV; >> >> drv = dev->driver; >> dev_info.device_flags = drv->device_flags; >> diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c >> index f3b6444c3..d965aafef 100644 >> --- a/kernel/cobalt/rtdm/fd.c >> +++ b/kernel/cobalt/rtdm/fd.c >> @@ -51,9 +51,9 @@ static int enosys(void) >> return -ENOSYS; >> } >> >> -static int enodev(void) >> +static int eadv(void) >> { >> -return -ENODEV; >> +return -EADV; >> } >> >> static void nop_close(struct rtdm_fd *fd) >> @@ -81,14 +81,14 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, >> int ufd) >> >> #define assign_invalid_handler(__handler) \ >> do \ >> -(__handler) = (typeof(__handler))enodev;\ >> +(__handler) = (typeof(__handler))eadv; \ >> while (0) >> >> -/* Calling this handler should beget ENODEV if not implemented. */ >> +/* Calling this handler should beget EADV if not implemented. */ >> #define assign_invalid_default_handler(__handler) \ >> do \ >> if ((__handler) == NULL)\ >> -(__handler) = (typeof(__handler))enodev;\ >> +(__handler) = (typeof(__handler))eadv; \ >> while (0) >> >> #define __assign_default_handler(__handler, __placeholder) \ >> @@ -105,7 +105,7 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, >> int ufd) >> #define __nrt(__handler) __handler ## _nrt >> >> /* >> - * Install a placeholder returning ENODEV if none of the dual handlers >> + * Install a placeholder returning EADV if none of the dual handlers >>* are implemented, ENOSYS otherwise for NULL handlers to trigger the >>* adaptive switch. >>*/ >> @@ -204,8 +204,14 @@ int rtdm_fd_register(struct rtdm_fd *fd, int ufd) >>* @param[in] ufd User-side file descriptor >>* @param[in] magic Magic word for lookup validation >>* >> - * @return Pointer to the RTDM file descriptor matching @a ufd, or >> - * ERR_PTR(-EBADF). >> + * @return Pointer to the RTDM file descriptor matching @a >> + * ufd. Otherw0ise: >> + * >> + * - ERR_PTR(-EADV) if the use-space handle is either invalid, or not >> + * managed by RTDM. >> + * >> + * - ERR_PTR(-EBADF) if the underlying device is being torned down at >> + * the time of the call. >>* >>* @note The file descriptor returned must be later released by a call >>* to rtdm_fd_put(). >> @@ -221,7 +227,7 @@ struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic) >> xnlock_get_irqsave(_lock, s); >> fd = fetch_fd(p, ufd); >> if (fd == NULL || (magic != 0 && fd->magic != magic)) { >> -fd = ERR_PTR(-EBADF); >> +fd = ERR_PTR(-EADV); >> goto out; >> } >> >> @@ -405,7 +411,7 @@ static struct rtdm_fd *get_fd_fixup_mode(int ufd) >> { >> struct xnthread *thread; >> struct rtdm_fd *fd; >> - >> + >> fd = rtdm_fd_get(ufd, 0); >> if (IS_ERR(fd)) >> return fd; >> @@ -470,7 +476,7 @@ int rtdm_fd_ioctl(int ufd, unsigned int request, ...) >> >> if (err < 0) { >> ret =
Re: [PATCH 1/2] drivers/net: Kconfig: fix tests for architecture
On 30.08.19 18:05, Philippe Gerum wrote: Signed-off-by: Philippe Gerum --- kernel/drivers/net/drivers/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/drivers/net/drivers/Kconfig b/kernel/drivers/net/drivers/Kconfig index 9ebc59a89..65f0855c1 100644 --- a/kernel/drivers/net/drivers/Kconfig +++ b/kernel/drivers/net/drivers/Kconfig @@ -77,7 +77,7 @@ config XENO_DRIVERS_NET_DRV_R8169 tristate "Realtek 8169 (Gigabit)" -if ARCH = ppc +if PPC comment "Embedded MPC Drivers" depends on XENO_DRIVERS_NET @@ -116,7 +116,7 @@ config XENO_DRIVERS_NET_DRV_SMC9 depends on XENO_DRIVERS_NET tristate "SMSC LAN91C111" -if ARCH = arm +if ARM config XENO_DRIVERS_NET_DRV_AT91_ETHER depends on XENO_DRIVERS_NET && SOC_AT91RM9200 Thanks, applied to next, queued for stable. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 2/2] cobalt/pipe: unblock read()/write() on disconnect
On 30.08.19 18:04, Philippe Gerum wrote: Threads waiting on read()/write() must be unblocked when the kernel endpoint is disconnected. read() should return 0, write() receives -EPIPE. Signed-off-by: Philippe Gerum --- kernel/cobalt/pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cobalt/pipe.c b/kernel/cobalt/pipe.c index 16e85125c..0c83095ba 100644 --- a/kernel/cobalt/pipe.c +++ b/kernel/cobalt/pipe.c @@ -132,7 +132,7 @@ static inline void xnpipe_dequeue_all(struct xnpipe_state *state, int mask) if (__sigpending) \ break; \ prepare_to_wait_exclusive(__waitq, &__wait, TASK_INTERRUPTIBLE); \ - if (__cond) \ + if (__cond || (__state)->status & XNPIPE_KERN_LCLOSE)\ break; \ schedule(); \ } \ Thanks, applied to next, queued for stable. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 2/2] cobalt/sched: tp: check partition id obtained from user
On 30.08.19 18:05, Philippe Gerum wrote: Signed-off-by: Philippe Gerum --- kernel/cobalt/sched-tp.c | 4 1 file changed, 4 insertions(+) diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c index d3e2586b0..ccff37428 100644 --- a/kernel/cobalt/sched-tp.c +++ b/kernel/cobalt/sched-tp.c @@ -168,6 +168,10 @@ static int xnsched_tp_chkparam(struct xnthread *thread, { struct xnsched_tp *tp = >sched->tp; + if (p->tp.ptid < 0 || + p->tp.ptid >= CONFIG_XENO_OPT_SCHED_TP_NRPART) + return -EINVAL; + if (tp->gps == NULL || p->tp.prio < XNSCHED_TP_MIN_PRIO || p->tp.prio > XNSCHED_TP_MAX_PRIO) Thanks, applied to next, queued for stable. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 1/2] drivers/net: drop socket-specific module refcounting
On 30.08.19 18:04, Philippe Gerum wrote: RTDM already refcounts rtdm_fd descriptors to prevent unsafe module unloading while connections are still active. We can remove the legacy module refcounting done by the generic socket code, since every socket is covered by an RTDM file descriptor. Signed-off-by: Philippe Gerum --- .../drivers/net/stack/include/rtnet_socket.h | 15 +++ kernel/drivers/net/stack/ipv4/icmp.c | 4 +-- kernel/drivers/net/stack/socket.c | 27 ++- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/kernel/drivers/net/stack/include/rtnet_socket.h b/kernel/drivers/net/stack/include/rtnet_socket.h index 351e62c77..0d8850c7f 100644 --- a/kernel/drivers/net/stack/include/rtnet_socket.h +++ b/kernel/drivers/net/stack/include/rtnet_socket.h @@ -76,8 +76,6 @@ struct rtsocket { int ifindex; } packet; } prot; - -struct module *owner; }; @@ -97,10 +95,7 @@ int rtnet_put_arg(struct rtdm_fd *fd, void *dst, #define rt_socket_dereference(sock) \ rtdm_fd_unlock(rt_socket_fd(sock)) -int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, - struct module *module); -#define rt_socket_init(fd, proto) \ -__rt_socket_init(fd, proto, THIS_MODULE) +int rt_socket_init(struct rtdm_fd *fd, unsigned short protocol); void rt_socket_cleanup(struct rtdm_fd *fd); int rt_socket_common_ioctl(struct rtdm_fd *fd, int request, void __user *arg); @@ -110,16 +105,12 @@ int rt_socket_select_bind(struct rtdm_fd *fd, enum rtdm_selecttype type, unsigned fd_index); -int __rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, - unsigned int priority, unsigned int pool_size, - struct module *module); -#define rt_bare_socket_init(fd, proto, prio, pool_sz) \ -__rt_bare_socket_init(fd, proto, prio, pool_sz, THIS_MODULE) +int rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, + unsigned int priority, unsigned int pool_size); static inline void rt_bare_socket_cleanup(struct rtsocket *sock) { rtskb_pool_release(>skb_pool); -module_put(sock->owner); } #endif /* __RTNET_SOCKET_H_ */ diff --git a/kernel/drivers/net/stack/ipv4/icmp.c b/kernel/drivers/net/stack/ipv4/icmp.c index 58d97cd7f..a944ef6b7 100644 --- a/kernel/drivers/net/stack/ipv4/icmp.c +++ b/kernel/drivers/net/stack/ipv4/icmp.c @@ -526,8 +526,8 @@ void __init rt_icmp_init(void) { int skbs; -skbs = __rt_bare_socket_init(icmp_fd, IPPROTO_ICMP, RT_ICMP_PRIO, - ICMP_REPLY_POOL_SIZE, NULL); +skbs = rt_bare_socket_init(icmp_fd, IPPROTO_ICMP, RT_ICMP_PRIO, + ICMP_REPLY_POOL_SIZE); BUG_ON(skbs < 0); if (skbs < ICMP_REPLY_POOL_SIZE) printk("RTnet: allocated only %d icmp rtskbs\n", skbs); diff --git a/kernel/drivers/net/stack/socket.c b/kernel/drivers/net/stack/socket.c index ce4e4cb46..747db052f 100644 --- a/kernel/drivers/net/stack/socket.c +++ b/kernel/drivers/net/stack/socket.c @@ -50,36 +50,27 @@ MODULE_PARM_DESC(socket_rtskbs, "Default number of realtime socket buffers in so * internal socket functions * / -int __rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, - unsigned int priority, unsigned int pool_size, - struct module *module) +int rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, + unsigned int priority, unsigned int pool_size) { struct rtsocket *sock = rtdm_fd_to_private(fd); int err; -err = try_module_get(module); -if (!err) - return -EAFNOSUPPORT; - err = rtskb_pool_init(>skb_pool, pool_size, NULL, fd); -if (err < 0) { - module_put(module); +if (err < 0) return err; -} sock->protocol = protocol; sock->priority = priority; -sock->owner = module; return err; } -EXPORT_SYMBOL_GPL(__rt_bare_socket_init); +EXPORT_SYMBOL_GPL(rt_bare_socket_init); /*** * rt_socket_init - initialises a new socket structure */ -int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, - struct module *module) +int rt_socket_init(struct rtdm_fd *fd, unsigned short protocol) { struct rtsocket *sock = rtdm_fd_to_private(fd); unsigned intpool_size; @@ -94,10 +85,10 @@ int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, rtdm_lock_init(>param_lock); rtdm_sem_init(>pending_sem, 0); -pool_size = __rt_bare_socket_init(fd, protocol, +pool_size = rt_bare_socket_init(fd, protocol, RTSKB_PRIO_VALUE(SOCK_DEF_PRIO,
Re: [PATCH v4 2/2] cobalt/rtdm: allow for device teardown
On 30.08.19 18:03, Philippe Gerum wrote: Currently, rtdm_dev_unregister() will hang soft until all references on the dismantled device have been dropped, which in turn cannot happen until all rtdm_fds on 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 prevents rtdm_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 from rtdm_dev_unregister(). Since a close() 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 --- 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(-) diff --git a/include/cobalt/kernel/list.h b/include/cobalt/kernel/list.h index 989d934b8..37b91b0d5 100644 --- a/include/cobalt/kernel/list.h +++ b/include/cobalt/kernel/list.h @@ -45,7 +45,7 @@ do { \ ({ \ __type *__item; \ __item = list_first_entry(__head, __type, __member); \ - list_del(&__item->__member); \ + list_del(&(__item)->__member); \ Not really needed, is it? Just trying to understand. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH v4 1/2] cobalt: switch hand over status to -EADV for non-RTDM fd
On 30.08.19 18:03, Philippe Gerum wrote: > Having the RTDM core return -EBADF to indicate that it does not manage > a file descriptor is a problem, as several drivers also raise this > error to notify userland about an aborted wait due to a connection > being dismantled (e.g. RTnet). In this case, libcobalt ends up > forwarding the aborted request to the glibc, which is wrong. > > Switch from -EBADF to -EADV to notify userland that RTDM does not > manage a file descriptor, which cannot conflict with any sensible > error code the Cobalt core or any RTDM driver may return. > > Signed-off-by: Philippe Gerum > --- > kernel/cobalt/rtdm/core.c | 4 ++-- > kernel/cobalt/rtdm/fd.c | 36 + > lib/cobalt/rtdm.c | 48 +++ > 3 files changed, 47 insertions(+), 41 deletions(-) > > diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c > index c1aedb3d0..28db7adb7 100644 > --- a/kernel/cobalt/rtdm/core.c > +++ b/kernel/cobalt/rtdm/core.c > @@ -154,7 +154,7 @@ int __rtdm_dev_open(const char *path, int oflag) >*/ > dev = __rtdm_get_namedev(path); > if (dev == NULL) > - return -ENODEV; > + return -EADV; > > ufd = get_unused_fd_flags(oflag); > if (ufd < 0) { > @@ -266,7 +266,7 @@ int __rtdm_dev_ioctl_core(struct rtdm_fd *fd, unsigned > int request, > struct rtdm_device_info dev_info; > > if (fd->magic != RTDM_FD_MAGIC || request != RTIOC_DEVICE_INFO) > - return -ENOSYS; > + return -EADV; > > drv = dev->driver; > dev_info.device_flags = drv->device_flags; > diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c > index f3b6444c3..d965aafef 100644 > --- a/kernel/cobalt/rtdm/fd.c > +++ b/kernel/cobalt/rtdm/fd.c > @@ -51,9 +51,9 @@ static int enosys(void) > return -ENOSYS; > } > > -static int enodev(void) > +static int eadv(void) > { > - return -ENODEV; > + return -EADV; > } > > static void nop_close(struct rtdm_fd *fd) > @@ -81,14 +81,14 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, int > ufd) > > #define assign_invalid_handler(__handler) \ > do \ > - (__handler) = (typeof(__handler))enodev;\ > + (__handler) = (typeof(__handler))eadv; \ > while (0) > > -/* Calling this handler should beget ENODEV if not implemented. */ > +/* Calling this handler should beget EADV if not implemented. */ > #define assign_invalid_default_handler(__handler) \ > do \ > if ((__handler) == NULL)\ > - (__handler) = (typeof(__handler))enodev;\ > + (__handler) = (typeof(__handler))eadv; \ > while (0) > > #define __assign_default_handler(__handler, __placeholder) \ > @@ -105,7 +105,7 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, int > ufd) > #define __nrt(__handler)__handler ## _nrt > > /* > - * Install a placeholder returning ENODEV if none of the dual handlers > + * Install a placeholder returning EADV if none of the dual handlers >* are implemented, ENOSYS otherwise for NULL handlers to trigger the >* adaptive switch. >*/ > @@ -204,8 +204,14 @@ int rtdm_fd_register(struct rtdm_fd *fd, int ufd) >* @param[in] ufd User-side file descriptor >* @param[in] magic Magic word for lookup validation >* > - * @return Pointer to the RTDM file descriptor matching @a ufd, or > - * ERR_PTR(-EBADF). > + * @return Pointer to the RTDM file descriptor matching @a > + * ufd. Otherw0ise: > + * > + * - ERR_PTR(-EADV) if the use-space handle is either invalid, or not > + * managed by RTDM. > + * > + * - ERR_PTR(-EBADF) if the underlying device is being torned down at > + * the time of the call. >* >* @note The file descriptor returned must be later released by a call >* to rtdm_fd_put(). > @@ -221,7 +227,7 @@ struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic) > xnlock_get_irqsave(_lock, s); > fd = fetch_fd(p, ufd); > if (fd == NULL || (magic != 0 && fd->magic != magic)) { > - fd = ERR_PTR(-EBADF); > + fd = ERR_PTR(-EADV); > goto out; > } > > @@ -405,7 +411,7 @@ static struct rtdm_fd *get_fd_fixup_mode(int ufd) > { > struct xnthread *thread; > struct rtdm_fd *fd; > - > + > fd = rtdm_fd_get(ufd, 0); > if (IS_ERR(fd)) > return fd; > @@ -470,7 +476,7 @@ int rtdm_fd_ioctl(int ufd, unsigned int request, ...) > > if (err < 0) { > ret = __rtdm_dev_ioctl_core(fd, request, arg); > - if (ret != -ENOSYS) > + if (ret != -EADV) >
[PATCH 2/2] cobalt/sched: tp: check partition id obtained from user
Signed-off-by: Philippe Gerum --- kernel/cobalt/sched-tp.c | 4 1 file changed, 4 insertions(+) diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c index d3e2586b0..ccff37428 100644 --- a/kernel/cobalt/sched-tp.c +++ b/kernel/cobalt/sched-tp.c @@ -168,6 +168,10 @@ static int xnsched_tp_chkparam(struct xnthread *thread, { struct xnsched_tp *tp = >sched->tp; + if (p->tp.ptid < 0 || + p->tp.ptid >= CONFIG_XENO_OPT_SCHED_TP_NRPART) + return -EINVAL; + if (tp->gps == NULL || p->tp.prio < XNSCHED_TP_MIN_PRIO || p->tp.prio > XNSCHED_TP_MAX_PRIO) -- 2.21.0
[PATCH 1/2] drivers/net: Kconfig: fix tests for architecture
Signed-off-by: Philippe Gerum --- kernel/drivers/net/drivers/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/drivers/net/drivers/Kconfig b/kernel/drivers/net/drivers/Kconfig index 9ebc59a89..65f0855c1 100644 --- a/kernel/drivers/net/drivers/Kconfig +++ b/kernel/drivers/net/drivers/Kconfig @@ -77,7 +77,7 @@ config XENO_DRIVERS_NET_DRV_R8169 tristate "Realtek 8169 (Gigabit)" -if ARCH = ppc +if PPC comment "Embedded MPC Drivers" depends on XENO_DRIVERS_NET @@ -116,7 +116,7 @@ config XENO_DRIVERS_NET_DRV_SMC9 depends on XENO_DRIVERS_NET tristate "SMSC LAN91C111" -if ARCH = arm +if ARM config XENO_DRIVERS_NET_DRV_AT91_ETHER depends on XENO_DRIVERS_NET && SOC_AT91RM9200 -- 2.21.0
[PATCH 2/2] cobalt/pipe: unblock read()/write() on disconnect
Threads waiting on read()/write() must be unblocked when the kernel endpoint is disconnected. read() should return 0, write() receives -EPIPE. Signed-off-by: Philippe Gerum --- kernel/cobalt/pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cobalt/pipe.c b/kernel/cobalt/pipe.c index 16e85125c..0c83095ba 100644 --- a/kernel/cobalt/pipe.c +++ b/kernel/cobalt/pipe.c @@ -132,7 +132,7 @@ static inline void xnpipe_dequeue_all(struct xnpipe_state *state, int mask) if (__sigpending) \ break; \ prepare_to_wait_exclusive(__waitq, &__wait, TASK_INTERRUPTIBLE); \ - if (__cond) \ + if (__cond || (__state)->status & XNPIPE_KERN_LCLOSE) \ break; \ schedule(); \ } \ -- 2.21.0
[PATCH 1/2] drivers/net: drop socket-specific module refcounting
RTDM already refcounts rtdm_fd descriptors to prevent unsafe module unloading while connections are still active. We can remove the legacy module refcounting done by the generic socket code, since every socket is covered by an RTDM file descriptor. Signed-off-by: Philippe Gerum --- .../drivers/net/stack/include/rtnet_socket.h | 15 +++ kernel/drivers/net/stack/ipv4/icmp.c | 4 +-- kernel/drivers/net/stack/socket.c | 27 ++- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/kernel/drivers/net/stack/include/rtnet_socket.h b/kernel/drivers/net/stack/include/rtnet_socket.h index 351e62c77..0d8850c7f 100644 --- a/kernel/drivers/net/stack/include/rtnet_socket.h +++ b/kernel/drivers/net/stack/include/rtnet_socket.h @@ -76,8 +76,6 @@ struct rtsocket { int ifindex; } packet; } prot; - -struct module *owner; }; @@ -97,10 +95,7 @@ int rtnet_put_arg(struct rtdm_fd *fd, void *dst, #define rt_socket_dereference(sock) \ rtdm_fd_unlock(rt_socket_fd(sock)) -int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, - struct module *module); -#define rt_socket_init(fd, proto) \ -__rt_socket_init(fd, proto, THIS_MODULE) +int rt_socket_init(struct rtdm_fd *fd, unsigned short protocol); void rt_socket_cleanup(struct rtdm_fd *fd); int rt_socket_common_ioctl(struct rtdm_fd *fd, int request, void __user *arg); @@ -110,16 +105,12 @@ int rt_socket_select_bind(struct rtdm_fd *fd, enum rtdm_selecttype type, unsigned fd_index); -int __rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, - unsigned int priority, unsigned int pool_size, - struct module *module); -#define rt_bare_socket_init(fd, proto, prio, pool_sz) \ -__rt_bare_socket_init(fd, proto, prio, pool_sz, THIS_MODULE) +int rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, + unsigned int priority, unsigned int pool_size); static inline void rt_bare_socket_cleanup(struct rtsocket *sock) { rtskb_pool_release(>skb_pool); -module_put(sock->owner); } #endif /* __RTNET_SOCKET_H_ */ diff --git a/kernel/drivers/net/stack/ipv4/icmp.c b/kernel/drivers/net/stack/ipv4/icmp.c index 58d97cd7f..a944ef6b7 100644 --- a/kernel/drivers/net/stack/ipv4/icmp.c +++ b/kernel/drivers/net/stack/ipv4/icmp.c @@ -526,8 +526,8 @@ void __init rt_icmp_init(void) { int skbs; -skbs = __rt_bare_socket_init(icmp_fd, IPPROTO_ICMP, RT_ICMP_PRIO, - ICMP_REPLY_POOL_SIZE, NULL); +skbs = rt_bare_socket_init(icmp_fd, IPPROTO_ICMP, RT_ICMP_PRIO, + ICMP_REPLY_POOL_SIZE); BUG_ON(skbs < 0); if (skbs < ICMP_REPLY_POOL_SIZE) printk("RTnet: allocated only %d icmp rtskbs\n", skbs); diff --git a/kernel/drivers/net/stack/socket.c b/kernel/drivers/net/stack/socket.c index ce4e4cb46..747db052f 100644 --- a/kernel/drivers/net/stack/socket.c +++ b/kernel/drivers/net/stack/socket.c @@ -50,36 +50,27 @@ MODULE_PARM_DESC(socket_rtskbs, "Default number of realtime socket buffers in so * internal socket functions * / -int __rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, - unsigned int priority, unsigned int pool_size, - struct module *module) +int rt_bare_socket_init(struct rtdm_fd *fd, unsigned short protocol, + unsigned int priority, unsigned int pool_size) { struct rtsocket *sock = rtdm_fd_to_private(fd); int err; -err = try_module_get(module); -if (!err) - return -EAFNOSUPPORT; - err = rtskb_pool_init(>skb_pool, pool_size, NULL, fd); -if (err < 0) { - module_put(module); +if (err < 0) return err; -} sock->protocol = protocol; sock->priority = priority; -sock->owner = module; return err; } -EXPORT_SYMBOL_GPL(__rt_bare_socket_init); +EXPORT_SYMBOL_GPL(rt_bare_socket_init); /*** * rt_socket_init - initialises a new socket structure */ -int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, - struct module *module) +int rt_socket_init(struct rtdm_fd *fd, unsigned short protocol) { struct rtsocket *sock = rtdm_fd_to_private(fd); unsigned intpool_size; @@ -94,10 +85,10 @@ int __rt_socket_init(struct rtdm_fd *fd, unsigned short protocol, rtdm_lock_init(>param_lock); rtdm_sem_init(>pending_sem, 0); -pool_size = __rt_bare_socket_init(fd, protocol, +pool_size = rt_bare_socket_init(fd, protocol, RTSKB_PRIO_VALUE(SOCK_DEF_PRIO, RTSKB_DEF_RT_CHANNEL), - socket_rtskbs,
[PATCH v4 2/2] cobalt/rtdm: allow for device teardown
Currently, rtdm_dev_unregister() will hang soft until all references on the dismantled device have been dropped, which in turn cannot happen until all rtdm_fds on 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 prevents rtdm_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 from rtdm_dev_unregister(). Since a close() 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 --- 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(-) diff --git a/include/cobalt/kernel/list.h b/include/cobalt/kernel/list.h index 989d934b8..37b91b0d5 100644 --- a/include/cobalt/kernel/list.h +++ b/include/cobalt/kernel/list.h @@ -45,7 +45,7 @@ do { \ ({ \ __type *__item; \ __item = list_first_entry(__head, __type, __member); \ - list_del(&__item->__member); \ + list_del(&(__item)->__member);\ __item; \ }) diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h index 72f75388d..3559a6f99 100644 --- a/include/cobalt/kernel/rtdm/driver.h +++ b/include/cobalt/kernel/rtdm/driver.h @@ -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; }; }; diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h index 572b17e29..30849fc79 100644 --- a/include/cobalt/kernel/rtdm/fd.h +++ b/include/cobalt/kernel/rtdm/fd.h @@ -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 0x5256 diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index 28db7adb7..b9b7319fe 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -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(>fd, ufd); + ret = rtdm_fd_register(>fd, ufd); + if (ret < 0) + return ret; + + xnlock_get_irqsave(, s); + list_add(>fd.next, >device->openfd_list); + xnlock_put_irqrestore(, 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(>fd, ufd); - ret = rtdm_fd_register(>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(>fd, ufd); -
[PATCH v4 1/2] cobalt: switch hand over status to -EADV for non-RTDM fd
Having the RTDM core return -EBADF to indicate that it does not manage a file descriptor is a problem, as several drivers also raise this error to notify userland about an aborted wait due to a connection being dismantled (e.g. RTnet). In this case, libcobalt ends up forwarding the aborted request to the glibc, which is wrong. Switch from -EBADF to -EADV to notify userland that RTDM does not manage a file descriptor, which cannot conflict with any sensible error code the Cobalt core or any RTDM driver may return. Signed-off-by: Philippe Gerum --- kernel/cobalt/rtdm/core.c | 4 ++-- kernel/cobalt/rtdm/fd.c | 36 + lib/cobalt/rtdm.c | 48 +++ 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index c1aedb3d0..28db7adb7 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -154,7 +154,7 @@ int __rtdm_dev_open(const char *path, int oflag) */ dev = __rtdm_get_namedev(path); if (dev == NULL) - return -ENODEV; + return -EADV; ufd = get_unused_fd_flags(oflag); if (ufd < 0) { @@ -266,7 +266,7 @@ int __rtdm_dev_ioctl_core(struct rtdm_fd *fd, unsigned int request, struct rtdm_device_info dev_info; if (fd->magic != RTDM_FD_MAGIC || request != RTIOC_DEVICE_INFO) - return -ENOSYS; + return -EADV; drv = dev->driver; dev_info.device_flags = drv->device_flags; diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c index f3b6444c3..d965aafef 100644 --- a/kernel/cobalt/rtdm/fd.c +++ b/kernel/cobalt/rtdm/fd.c @@ -51,9 +51,9 @@ static int enosys(void) return -ENOSYS; } -static int enodev(void) +static int eadv(void) { - return -ENODEV; + return -EADV; } static void nop_close(struct rtdm_fd *fd) @@ -81,14 +81,14 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, int ufd) #define assign_invalid_handler(__handler) \ do \ - (__handler) = (typeof(__handler))enodev;\ + (__handler) = (typeof(__handler))eadv; \ while (0) -/* Calling this handler should beget ENODEV if not implemented. */ +/* Calling this handler should beget EADV if not implemented. */ #define assign_invalid_default_handler(__handler) \ do \ if ((__handler) == NULL)\ - (__handler) = (typeof(__handler))enodev;\ + (__handler) = (typeof(__handler))eadv; \ while (0) #define __assign_default_handler(__handler, __placeholder) \ @@ -105,7 +105,7 @@ static struct rtdm_fd *fetch_fd(struct cobalt_ppd *p, int ufd) #define __nrt(__handler) __handler ## _nrt /* - * Install a placeholder returning ENODEV if none of the dual handlers + * Install a placeholder returning EADV if none of the dual handlers * are implemented, ENOSYS otherwise for NULL handlers to trigger the * adaptive switch. */ @@ -204,8 +204,14 @@ int rtdm_fd_register(struct rtdm_fd *fd, int ufd) * @param[in] ufd User-side file descriptor * @param[in] magic Magic word for lookup validation * - * @return Pointer to the RTDM file descriptor matching @a ufd, or - * ERR_PTR(-EBADF). + * @return Pointer to the RTDM file descriptor matching @a + * ufd. Otherwise: + * + * - ERR_PTR(-EADV) if the use-space handle is either invalid, or not + * managed by RTDM. + * + * - ERR_PTR(-EBADF) if the underlying device is being torned down at + * the time of the call. * * @note The file descriptor returned must be later released by a call * to rtdm_fd_put(). @@ -221,7 +227,7 @@ struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic) xnlock_get_irqsave(_lock, s); fd = fetch_fd(p, ufd); if (fd == NULL || (magic != 0 && fd->magic != magic)) { - fd = ERR_PTR(-EBADF); + fd = ERR_PTR(-EADV); goto out; } @@ -405,7 +411,7 @@ static struct rtdm_fd *get_fd_fixup_mode(int ufd) { struct xnthread *thread; struct rtdm_fd *fd; - + fd = rtdm_fd_get(ufd, 0); if (IS_ERR(fd)) return fd; @@ -470,7 +476,7 @@ int rtdm_fd_ioctl(int ufd, unsigned int request, ...) if (err < 0) { ret = __rtdm_dev_ioctl_core(fd, request, arg); - if (ret != -ENOSYS) + if (ret != -EADV) err = ret; } @@ -814,13 +820,13 @@ int rtdm_fd_close(int ufd, unsigned int magic) xnlock_get_irqsave(_lock, s); idx = fetch_fd_index(ppd, ufd); if (idx == NULL) - goto ebadf; +
[I-PIPE] ipipe-core-4.4.188-cip36-x86-17 released
Download URL: https://xenomai.org/downloads/ipipe/v4.x/x86/ipipe-core-4.4.188-cip36-x86-17.patch Repository: https://git.xenomai.org/ipipe-x86 Release tag: ipipe-core-4.4.188-cip36-x86-17
Re: missing compat version of rt_task_set_periodic
On 30.08.19 17:00, Tormod Volden via Xenomai wrote: Hi, I am porting an old RTNet / RTAI (3.8.1) application to latest xenomai (currently using git master). For this I chose the alchemy skin, and to make it as close as possible to the old API, I am also trying to enable the --compat transition kit. However, rt_task_set_periodic() disappears as soon as I add --compat. I am not sure whether it is an include file / macro bug or if I am not using it correctly, so I hope you can give me a hint. xenomai was built from git master, with --configure --with-core=cobalt and installed. $ xeno-config --skin=alchemy --compat --cflags -I/usr/xenomai/include/trank -D__XENO_COMPAT__ -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ -I/usr/xenomai/include/alchemy Here is a small compile test program: $ cat xeno_compat_test.c #include In compat mode, the prototype comes via native/task.h again. Jan void test(void) { rt_task_set_periodic(NULL, TM_NOW, 0); } Using only --alchemy works fine: $ gcc -c xeno_compat_test.c $(xeno-config --skin=alchemy --cflags) $ However, with --compat it fails: $ gcc -c xeno_compat_test.c $(xeno-config --skin=alchemy --compat --cflags) xeno_compat_test.c: In function ‘test’: xeno_compat_test.c:6:3: warning: implicit declaration of function ‘rt_task_set_periodic’; did you mean ‘rt_task_set_priority’? [-Wimplicit-function-declaration] rt_task_set_periodic(NULL, TM_NOW, 0); ^~~~ rt_task_set_priority Using --skin=native gives the same result as --compat. I found out that I can use __current_rt_task_set_periodic() to force the use of the "new" function, but I could't get something like __compat_rt_task_set_periodic() to work. -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
missing compat version of rt_task_set_periodic
Hi, I am porting an old RTNet / RTAI (3.8.1) application to latest xenomai (currently using git master). For this I chose the alchemy skin, and to make it as close as possible to the old API, I am also trying to enable the --compat transition kit. However, rt_task_set_periodic() disappears as soon as I add --compat. I am not sure whether it is an include file / macro bug or if I am not using it correctly, so I hope you can give me a hint. xenomai was built from git master, with --configure --with-core=cobalt and installed. $ xeno-config --skin=alchemy --compat --cflags -I/usr/xenomai/include/trank -D__XENO_COMPAT__ -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ -I/usr/xenomai/include/alchemy Here is a small compile test program: $ cat xeno_compat_test.c #include void test(void) { rt_task_set_periodic(NULL, TM_NOW, 0); } Using only --alchemy works fine: $ gcc -c xeno_compat_test.c $(xeno-config --skin=alchemy --cflags) $ However, with --compat it fails: $ gcc -c xeno_compat_test.c $(xeno-config --skin=alchemy --compat --cflags) xeno_compat_test.c: In function ‘test’: xeno_compat_test.c:6:3: warning: implicit declaration of function ‘rt_task_set_periodic’; did you mean ‘rt_task_set_priority’? [-Wimplicit-function-declaration] rt_task_set_periodic(NULL, TM_NOW, 0); ^~~~ rt_task_set_priority Using --skin=native gives the same result as --compat. I found out that I can use __current_rt_task_set_periodic() to force the use of the "new" function, but I could't get something like __compat_rt_task_set_periodic() to work. Best regards, Tormod
[I-PIPE] ipipe-core-4.19.66-x86-6 released
Download URL: https://xenomai.org/downloads/ipipe/v4.x/x86/ipipe-core-4.19.66-x86-6.patch Repository: https://git.xenomai.org/ipipe-x86 Release tag: ipipe-core-4.19.66-x86-6
[I-PIPE] ipipe-core-4.19.66-cip9-x86-6 released
Download URL: https://xenomai.org/downloads/ipipe/v4.x/x86/ipipe-core-4.19.66-cip9-x86-6.patch Repository: https://git.xenomai.org/ipipe-x86 Release tag: ipipe-core-4.19.66-cip9-x86-6
Re: i-pipe tracer - how to view traced data
On 30.08.19 14:01, Laurentiu-Cristian Duca wrote: Hello and thank you for the answer. It worked. Here is a test of rtt-responder on qemu. I also attached it to this email. I use the ipipe-trace api to freeze tracing from C code. I see that rtdm_fd_recvmsg and rtdm_fd_sendmsg are called (and I wanted to see that). I have some questions (I have some ideas but just want to be sure). Please answer to those that are important. 1. On Hard IRQs column, I see only ':' and space; what do they mean? What does mean ('|': locked) from Hard IRQs? Actually, you see ':' and eventually a '<' in the very first column. That marks the path of a trace, down to the 'freeze'. In the second column, IRQs-off are marked as '|'. 2. On Xenomai column I see only '|' and space; what do they mean? See above: that was the hard-IRQs off column. 3. What does the following column mean: Linux ('*': domain stalled, '+': current, '#': current+stalled) "Stalled" means "interrupts virtually off". "Current" means that this pipeline stage is currently active. When a more left stage is active, a more right one will not get events or interrupts. We only have two stages here, Linux and Xenomai. In the old times, there could be more. 4. Type 'func' I think it means a function is called; correct? Correct. What do 'begin' and 'end' mean on the Type column? Are they important? There is ipipe_trace_begin and ..._end which we added to hard-irq state changes (CONFIG_IPIPE_TRACE_IRQSOFF). The tracer automatically records the longer path between a begin and an end, providing that as trace via the "max" virtual file. The tracepoints are visible in frozen traces as well, though. 5. NMI noise 'N' ? The ipipe tracer does not support recursion. So, if you are in a trace point recording call already and an NMI hits, that path will not be recorded in details, but the "NMI noise" flag will be set on the interrupted trace point. In practice, you will rarely see such a case, specifically as NMIs are very rare under normal conditions (not with perf, though). HTH, Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: i-pipe tracer - how to view traced data
Hello and thank you for the answer. It worked. Here is a test of rtt-responder on qemu. I also attached it to this email. I use the ipipe-trace api to freeze tracing from C code. I see that rtdm_fd_recvmsg and rtdm_fd_sendmsg are called (and I wanted to see that). I have some questions (I have some ideas but just want to be sure). Please answer to those that are important. 1. On Hard IRQs column, I see only ':' and space; what do they mean? What does mean ('|': locked) from Hard IRQs? 2. On Xenomai column I see only '|' and space; what do they mean? 3. What does the following column mean: Linux ('*': domain stalled, '+': current, '#': current+stalled) 4. Type 'func' I think it means a function is called; correct? What do 'begin' and 'end' mean on the Type column? Are they important? 5. NMI noise 'N' ? I-pipe frozen back-tracing service on 4.14.71/ipipe release #2112 CPU: 0, Freeze: 1176197529135 cycles, Trace Points: 100 (+10) Calibrated minimum trace-point overhead: 0.074 us +- Hard IRQs ('|': locked) |+-- Xenomai ||+- Linux ('*': domain stalled, '+': current, '#': current+stalled) ||| +-- Delay flag ('+': > 1 us, '!': > 10 us) ||| |+- NMI noise ('N') ||| || TypeUser Val. TimeDelay Function (Parent) :|# func -27 0.574 xnsynch_wakeup_one_sleeper+0x0 (rtdm_sem_up+0xed) :|# func -26 0.406 xnthread_resume+0x0 (xnsynch_wakeup_one_sleeper+0x14a) :|# [ 121] rtt-res 81 -26 0.184 xnthread_resume+0x113 (<>) :|# func -26 0.149 xnsched_rt_enqueue+0x0 (xnthread_resume+0x14f) :|# func -26 0.335 xnsched_addq_tail+0x0 (xnthread_resume+0x14f) :|# func -25 0.185 ___xnsched_run+0x0 (rtdm_sem_up+0x18d) :|# func -25 0.202 ___xnsched_run.part.63+0x0 (rtdm_sem_up+0x18d) :|# [ 100] rtnet-s 98 -25 0.165 ___xnsched_run.part.63+0x102 (<>) :|# func -25 0.207 xnsched_pick_next+0x0 (___xnsched_run.part.63+0x137) :|# func -25 0.160 xnsched_rt_requeue+0x0 (xnsched_pick_next+0x56) :|# func -24 0.193 xnsched_addq+0x0 (xnsched_pick_next+0x56) :|# func -24 0.165 xnsched_rt_pick+0x0 (xnsched_pick_next+0x8b) :|# func -24 0.200 del_q+0x0 (xnsched_rt_pick+0x5a) :|# func -24 0.198 xnlock_dbg_release+0x0 (rtdm_sem_up+0x1b2) :|# func -24 0.156 __ipipe_restore_head+0x0 (rtdm_sem_up+0x14c) :|+ end 0x8000 -23 0.142 __ipipe_restore_head+0x4d (<>) :|+ begin 0x8000 -23 0.193 rt_udp_rcv+0xe4 [rtudp] (<>) :|# func -23 0.156 xnsched_lock+0x0 (rt_udp_rcv+0x11c [rtudp]) :|# func -23 0.185 xnsched_unlock+0x0 (rt_udp_rcv+0x136 [rtudp]) :|# func -23 0.156 __ipipe_restore_head+0x0 (rt_udp_rcv+0x15a [rtudp]) :|+ end 0x8000 -23 0.209 __ipipe_restore_head+0x4d (<>) : + func -22 0.153 rtdm_fd_unlock+0x0 (rt_ip_rcv+0x15a [rtipv4]) :|+ begin 0x8000 -22 0.189 rtdm_fd_unlock+0x22 (<>) :|# func -22 0.160 xnlock_dbg_prepare_acquire+0x0 (rtdm_fd_unlock+0x54) :|# func -22 0.193 xnlock_dbg_acquired+0x0 (rtdm_fd_unlock+0x92) :|# func -22 0.169 __put_fd+0x0 (rtdm_fd_unlock+0xa4) :|# func -22 0.180 xnlock_dbg_release+0x0 (__put_fd+0xa8) :|# func -21 0.158 __ipipe_restore_head+0x0 (__put_fd+0x6f) :|+ end 0x8000 -21 0.169 __ipipe_restore_head+0x4d (<>) :|+ begin 0x8000 -21 0.191 rt_stack_deliver+0x293 [rtnet] (<>) :|# func -21 0.267 xnsched_lock+0x0 (rt_stack_deliver+0x2c8 [rtnet]) :|# func -21 0.313 module_put+0x0 (rt_stack_deliver+0x2d4 [rtnet]) :|# func -20 0.225 xnsched_unlock+0x0 (rt_stack_deliver+0x2e8 [rtnet]) :|# func -20 0.153 __ipipe_restore_head+0x0 (rt_stack_mgr_task+0x6b [rtnet]) :|+ end 0x8000 -20 0.184 __ipipe_restore_head+0x4d (<>) : + func -20 0.162 rtdm_event_wait+0x0 (rt_stack_mgr_task+0x2c [rtnet]) : + func -20 0.236 rtdm_event_timedwait+0x0 (rt_stack_mgr_task+0x2c [rtnet]) :|+ begin 0x8000 -19 0.194 rtdm_event_timedwait+0xb1 (<>) :|# func -19 0.154 xnlock_dbg_prepare_acquire+0x0 (rtdm_event_timedwait+0xed) :|# func -19 0.200 xnlock_dbg_acquired+0x0 (rtdm_event_timedwait+0x131) :|# func -19 0.344 xnsynch_sleep_on+0x0 (rtdm_event_timedwait+0x316) :|# func -18 0.315
Re: [PATCH 2/2] cobalt: switch hand over status to -ENODEV for non-RTDM fd
On 30.08.19 11:58, Lange Norbert wrote: -Original Message- From: Jan Kiszka Sent: Donnerstag, 29. August 2019 16:52 To: Lange Norbert ; Philippe Gerum ; Xenomai (xenomai@xenomai.org) Subject: Re: [PATCH 2/2] cobalt: switch hand over status to -ENODEV for non- RTDM fd E-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS. On 29.08.19 16:12, Lange Norbert via Xenomai wrote: I ran into a rather big issue with linux filehandles I use Xenomai master on ipipe-core-4.19.60-x86-5 with those patches, (can't be 100% sure its not some kernel/userspace conflict, but I doubt it) What happens is that upon a __cobalt_close with a linux filehande, the syscall sc_cobalt_close returns EBADF, but that means the libc close will never be tried and filehandles are leaking like mad. Ah, good catch. Looks like Philippe's patch was missing a change to rtdm_fd_close(). Yes, but his v3 works. Thanks a lot for testing pro-actively! You are welcome, its less benign than you might think though, Philippe's patches (allow for device teardown) were requested from myself. How does Xenomai/cobalt handle kernel/userspace conflicts like these BTW, Is there some ABI variable that needs to be incremented and can detect mismatches? (if you use an old libcobalt on a new kernel module with patchset or vice verse, it would result in leaks or other issues) There is an ABI revision check between kernel and userland, and there are feature checks. We will likely need an ABI bump here, which did not take place in master so far (compared to 3.0). Follow XENOMAI_ABI_REV on that. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
RE: [PATCH 2/2] cobalt: switch hand over status to -ENODEV for non-RTDM fd
> -Original Message- > From: Jan Kiszka > Sent: Donnerstag, 29. August 2019 16:52 > To: Lange Norbert ; Philippe Gerum > ; Xenomai (xenomai@xenomai.org) > > Subject: Re: [PATCH 2/2] cobalt: switch hand over status to -ENODEV for non- > RTDM fd > > E-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE > EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR > ATTACHMENTS. > > > On 29.08.19 16:12, Lange Norbert via Xenomai wrote: > > > > I ran into a rather big issue with linux filehandles I use Xenomai > > master on ipipe-core-4.19.60-x86-5 with those patches, (can't be 100% > > sure its not some kernel/userspace conflict, but I doubt it) > > > > What happens is that upon a __cobalt_close with a linux filehande, the > > syscall sc_cobalt_close returns EBADF, but that means the libc close > > will never be tried and filehandles are leaking like mad. > > > > Ah, good catch. Looks like Philippe's patch was missing a change to > rtdm_fd_close(). Yes, but his v3 works. > Thanks a lot for testing pro-actively! You are welcome, its less benign than you might think though, Philippe's patches (allow for device teardown) were requested from myself. How does Xenomai/cobalt handle kernel/userspace conflicts like these BTW, Is there some ABI variable that needs to be incremented and can detect mismatches? (if you use an old libcobalt on a new kernel module with patchset or vice verse, it would result in leaks or other issues) Kind regards, Norbert This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system. ANDRITZ HYDRO GmbH Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation Firmensitz/ Registered seat: Wien Firmenbuchgericht/ Court of registry: Handelsgericht Wien Firmenbuchnummer/ Company registration: FN 61833 g DVR: 0605077 UID-Nr.: ATU14756806 Thank You