From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by dpdk.org (Postfix) with ESMTP id C3E798E68; Tue, 17 Apr 2018 06:02:15 +0200 (CEST) Received: by mail-pl0-f65.google.com with SMTP id 59-v6so11227353plc.13; Mon, 16 Apr 2018 21:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YaQcWXZp6RFcnVX5IHl58Szc/cuj23peoj9HMEf9Lnk=; b=sQMsp4Ybmj8ejuUME5tXH8qtbx8L9L/JTen7Nb3/G01fwbjbsbgpb6FJhJwnGw/n9V MekwQOE/gVhED8Kpm+YS5R4QqBxBr3HRi8CoQv5uW7kJkTcOlE4z01AYi3+RjcPrXRpB ehY0i8DIuXIuKYApyrc2gfAcXvUd54NxVu9UjkoIJvVt4gVrxRjNWkz8ZrIK9LIOYo4n PNkPtUqJNEyjoKYD35CfJ5GowNKLN8bpT4OKd0wqzrx25QVa7bYVsp95LC1k1XH5NQK/ tWLcxwsJVSy+p6CDQjAN/ZCyIxO2jJq2gJIkiBBTmhGv5/iiN6xqJvkG6Vr8Y+hBrVMg YjrA== 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:in-reply-to :references; bh=YaQcWXZp6RFcnVX5IHl58Szc/cuj23peoj9HMEf9Lnk=; b=YCvLacshE/9afoZpEzh9Gj+6grGlN+F10CwqsA18uWHBSWB1q5fXuX+l5s/OX1n5sD o7hUEygafGf76SRe/4kFvxTok7UkpVJP3WI7g+/pR91tqCvSSixw/F1LzbQHmH/ZW7Fn oac0tdyERnMhbi6kNMb7RQYzTzNOEZYHUaQ2UNMJDbD4YGIvyEk4jh5/ibEgrbbF23zJ Dn3pcfmFeol1hwRT08/Ah5w8CTxwmgI6kUNnpJwxaa6GInWNS4fEnAaoH8UAXoEoH5As OpJ1GS2QoBtrZ3ShcQRpyGbYMAYQYvkn5YG4/y0e0TWUoWr5pum1ykZK9BHMlWXJKtXd yiMQ== X-Gm-Message-State: ALQs6tA1cXLvBhihPy3ozN/o69+Btppxmuv0yNfvkBse7v/Fzv6Rk7DO PXQu+HOxll1jLyAKNvYWOAlmcfsq X-Google-Smtp-Source: AIpwx49Qv45xT6QI/cf+0yZiKyqVc0k9SIHuoNhumh9wxl3oKWJ5fR0u1jxbF/7xDVs5jY1w4Lxlhw== X-Received: by 2002:a17:902:30f:: with SMTP id 15-v6mr489799pld.365.1523937734681; Mon, 16 Apr 2018 21:02:14 -0700 (PDT) Received: from localhost.localdomain (176.122.150.126.16clouds.com. [176.122.150.126]) by smtp.gmail.com with ESMTPSA id j11sm23487424pgc.91.2018.04.16.21.02.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 21:02:14 -0700 (PDT) From: Yangchao Zhou To: dev@dpdk.org Cc: stable@dpdk.org, ferruh.yigit@intel.com, thomas@monjalon.net Date: Tue, 17 Apr 2018 12:01:40 +0800 Message-Id: <1523937700-13716-1-git-send-email-zhouyates@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <2191a738-7443-464e-8600-eedcaf160593@zyc-PC.local> References: <2191a738-7443-464e-8600-eedcaf160593@zyc-PC.local> Subject: [dpdk-dev] [PATCH v3] kni: fix possible rx_q mbuf leaks and speed up alloc_q release 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: , X-List-Received-Date: Tue, 17 Apr 2018 04:02:16 -0000 rx_q fifo can only be released by kernel thread. There may be mbuf leaks in rx_q because kernel threads are randomly stopped. When the kni is released and netdev is unregisterd, convert the physical address mbufs in rx_q to the virtual address in free_q. By the way, alloc_q can be processed together to speed up the release rate in userspace. Signed-off-by: Yangchao Zhou Suggested-by: Ferruh Yigit --- kernel/linux/kni/kni_dev.h | 1 + kernel/linux/kni/kni_misc.c | 2 ++ kernel/linux/kni/kni_net.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 0 deletions(-) diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h index c9393d8..6275ef2 100644 --- a/kernel/linux/kni/kni_dev.h +++ b/kernel/linux/kni/kni_dev.h @@ -92,6 +92,7 @@ struct kni_dev { void *alloc_va[MBUF_BURST_SZ]; }; +void kni_net_release_fifo_phy(struct kni_dev *kni); void kni_net_rx(struct kni_dev *kni); void kni_net_init(struct net_device *dev); void kni_net_config_lo_mode(char *lo_str); diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c index 01574ec..fa69f8e 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -192,6 +192,8 @@ struct kni_net { free_netdev(dev->net_dev); } + kni_net_release_fifo_phy(dev); + return 0; } diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c index 9f9b798..1d64d78 100644 --- a/kernel/linux/kni/kni_net.c +++ b/kernel/linux/kni/kni_net.c @@ -163,6 +163,46 @@ return (ret == 0) ? req.result : ret; } +static void +kni_fifo_trans_pa2va(struct kni_dev *kni, + struct rte_kni_fifo *src_pa, struct rte_kni_fifo *dst_va) +{ + uint32_t ret, i, num_fq, num_rx; + void *kva; + do { + num_fq = kni_fifo_free_count(kni->free_q); + if (num_fq == 0) + return; + + num_rx = min_t(uint32_t, num_fq, MBUF_BURST_SZ); + + num_rx = kni_fifo_get(src_pa, kni->pa, num_rx); + if (num_rx == 0) + return; + + for (i = 0; i < num_rx; i++) { + kva = pa2kva(kni->pa[i]); + kni->va[i] = pa2va(kni->pa[i], kva); + } + + ret = kni_fifo_put(dst_va, kni->va, num_rx); + if (ret != num_rx) { + /* Failing should not happen */ + pr_err("Fail to enqueue entries into dst_va\n"); + return; + } + } while (1); +} + +/* Try to release mbufs when kni release */ +void kni_net_release_fifo_phy(struct kni_dev *kni) +{ + /* release rx_q first, because it can't release in userspace */ + kni_fifo_trans_pa2va(kni, kni->rx_q, kni->free_q); + /* release alloc_q for speeding up kni release in userspace */ + kni_fifo_trans_pa2va(kni, kni->alloc_q, kni->free_q); +} + /* * Configuration changes (passed on by ifconfig) */ -- 1.7.1