From patchwork Wed Apr 22 01:01:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 69066 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5D57CA05A1; Wed, 22 Apr 2020 03:02:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5C5871D51E; Wed, 22 Apr 2020 03:02:07 +0200 (CEST) Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by dpdk.org (Postfix) with ESMTP id B6A5C1D417 for ; Wed, 22 Apr 2020 03:02:05 +0200 (CEST) Received: by mail-pj1-f65.google.com with SMTP id a22so139217pjk.5 for ; Tue, 21 Apr 2020 18:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g9W+q5XMKL7zsj6ffyWkAJaxb6ZO1vWYb74KTS1aTxE=; b=AGqdB2CCgv89mNg4vHo4sYuiywOG+eXCD0HrEwlf8uhyvXw/I0RB5RrvQypoV1TEam bd76oVp0iojBSoy3dJJbb9YjZI+IeB6P843U4390P4BVGKEZVgqvDu+a0gfuL7693I32 LorHS4L5vfwMqFQQEanYlyCR2771sTg9Teg+J/GeJCB8P0w4d2TAgddL2Je1eR3EVcdp Ooblgf4abYWREDV3caPR0cdRiOx+x/76hpiQDT+VbUSa6N4lRCJRwyNJ0LEA0msawWNc VIscNltwHm9eElXbTt1Hxh7XzZebyBnhjRhu4A4ebcl1WWozQYraag4Zfjczf5rvRYn/ n1Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g9W+q5XMKL7zsj6ffyWkAJaxb6ZO1vWYb74KTS1aTxE=; b=siBt1ixLQsUndjftdQWbABURTdLGZi2Q8yIZW1LRTfYZK4H6n+GZ7TbTVit7vTX+43 TXLl+kWmg3uiQaBmXZwkS/Ytp1MvXlJNgtT4i9l6Fex5Z3gdjJPLCmoZmPsTo+Me61SQ 536OzUTdLmv/KPlwSr8B2XjAtPkPDGVv6Fl4L1JR9ycJmI45qfxMp1wiBpV2Y3ZNa/V9 oh6/ISuraDkssgI79Jva/fXApkIoKBLWj2eKyoVVjEr7Z8pOmlK3FDI0+1M767KJekFY NxGtjxf2nBnOMUc3CTENb70ouAMOYbGzNzK0J8FLhXSW9UzcWI8EyIueznxCILXU8jiQ bOyg== X-Gm-Message-State: AGi0PuZPt1pIOlkIexWJ5LkCERcsxnP08eEEaOBPslCAgNkQcXdyigaL WQA1l/GN9S3Vg+FF0z0w+SE2yfVupa7meg== X-Google-Smtp-Source: APiQypJ0CQumDXrkOUCdAAIuRktiimtFmMmq/+LntdURx9Nm+WfP4i1f8rcy4WL55jKoLjUdFUqlUg== X-Received: by 2002:a17:902:b617:: with SMTP id b23mr25552847pls.194.1587517324114; Tue, 21 Apr 2020 18:02:04 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o63sm3790768pjb.40.2020.04.21.18.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 18:02:03 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 21 Apr 2020 18:01:56 -0700 Message-Id: <20200422010156.1956-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [dpdk-dev] [RFC] net/tap: avoid using SIGIO X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The TAP device uses Linux signal internally to wakeup. The use of SIGIO is problematic because it maybe used by application. Instead choose another rt-signal since Linux allows any signal to be used for signal based IO. Search for an unused signal in the available rt-signal range. Add more error checking for fcntl and signal handling. Note: TAP is unique to Linux, BSD and Windows based TAP devices have different API's so the whole driver will need major rework if it ever used there. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 99 ++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 05470a211588..c71bb19801df 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -134,7 +134,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) #ifdef IFF_MULTI_QUEUE unsigned int features; #endif - int fd; + int fd, signo, flags; memset(&ifr, 0, sizeof(struct ifreq)); @@ -199,52 +199,87 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) } } + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + TAP_LOG(WARNING, + "Unable to get %s current flags\n", + ifr.ifr_name); + goto error; + } + /* Always set the file descriptor to non-blocking */ - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + flags |= O_NONBLOCK; + if (fcntl(fd, F_SETFL, flags) < 0) { TAP_LOG(WARNING, "Unable to set %s to nonblocking: %s", ifr.ifr_name, strerror(errno)); goto error; } - /* Set up trigger to optimize empty Rx bursts */ - errno = 0; - do { + /* Find a free realtime signal */ + for (signo = SIGRTMIN + 1; signo < SIGRTMAX; signo++) { struct sigaction sa; - int flags = fcntl(fd, F_GETFL); - if (flags == -1 || sigaction(SIGIO, NULL, &sa) == -1) + if (sigaction(signo, NULL, &sa) == -1) { + TAP_LOG(WARNING, + "Unable to get current rt-signal %d handler", + signo); + goto error; + } + + /* Already have the handler we want on this signal */ + if (sa.sa_handler == tap_trigger_cb) break; - if (sa.sa_handler != tap_trigger_cb) { - /* - * Make sure SIGIO is not already taken. This is done - * as late as possible to leave the application a - * chance to set up its own signal handler first. - */ - if (sa.sa_handler != SIG_IGN && - sa.sa_handler != SIG_DFL) { - errno = EBUSY; - break; - } - sa = (struct sigaction){ - .sa_flags = SA_RESTART, - .sa_handler = tap_trigger_cb, - }; - if (sigaction(SIGIO, &sa, NULL) == -1) - break; + + /* Is handler in use by application */ + if (sa.sa_handler != SIG_DFL) { + TAP_LOG(DEBUG, + "Skipping used rt-signal %d", signo); + continue; + } + + sa = (struct sigaction) { + .sa_flags = SA_RESTART, + .sa_handler = tap_trigger_cb, + }; + + if (sigaction(signo, &sa, NULL) == -1) { + TAP_LOG(WARNING, + "Unable to set rt-signal %d handler\n", signo); + goto error; } - /* Enable SIGIO on file descriptor */ - fcntl(fd, F_SETFL, flags | O_ASYNC); - fcntl(fd, F_SETOWN, getpid()); - } while (0); - if (errno) { + /* Found a good signal to use */ + TAP_LOG(DEBUG, + "Using rt-signal %d", signo); + break; + } + + if (signo == SIGRTMAX) { + TAP_LOG(WARNING, "All rt-signals are in use\n"); + /* Disable trigger globally in case of error */ tap_trigger = 0; - TAP_LOG(WARNING, "Rx trigger disabled: %s", - strerror(errno)); - } + TAP_LOG(NOTICE, "No Rx trigger signal available\n"); + } else { + /* Enable signal on file descriptor */ + if (fcntl(fd, F_SETSIG, signo) < 0) { + TAP_LOG(WARNING, "Unable to set signo %d for fd %d: %s", + signo, fd, strerror(errno)); + goto error; + } + if (fcntl(fd, F_SETFL, flags | O_ASYNC) < 0) { + TAP_LOG(WARNING, "Unable to set fcntl flags: %s", + strerror(errno)); + goto error; + } + if (fcntl(fd, F_SETOWN, getpid()) < 0) { + TAP_LOG(WARNING, "Unable to set fcntl owner: %s", + strerror(errno)); + goto error; + } + } return fd; error: