From: Hemant Agrawal <hemant.agrawal@nxp.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>
Subject: [dpdk-dev] [RFC PATCH 5/5] kni: support multiple userspace process working with kni module
Date: Wed, 3 May 2017 16:51:12 +0530 [thread overview]
Message-ID: <1493810472-668-5-git-send-email-hemant.agrawal@nxp.com> (raw)
In-Reply-To: <1493810472-668-1-git-send-email-hemant.agrawal@nxp.com>
in case of multiple application using the same KNI module,
protect that one application will only clean it's own devices.
Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
lib/librte_eal/linuxapp/kni/kni_dev.h | 1 +
lib/librte_eal/linuxapp/kni/kni_misc.c | 21 +++++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/lib/librte_eal/linuxapp/kni/kni_dev.h b/lib/librte_eal/linuxapp/kni/kni_dev.h
index 72385ab..c8c856d 100644
--- a/lib/librte_eal/linuxapp/kni/kni_dev.h
+++ b/lib/librte_eal/linuxapp/kni/kni_dev.h
@@ -61,6 +61,7 @@ struct kni_dev {
uint32_t core_id; /* Core ID to bind */
char name[RTE_KNI_NAMESIZE]; /* Network device name */
struct task_struct *pthread;
+ void *usrctxt; /* User space process context*/
/* wait queue for req/resp */
wait_queue_head_t wq;
diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index 4f99a5e..84f8a99 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -234,6 +234,9 @@ struct kni_net {
down_write(&knet->kni_list_lock);
list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
+ /* check for the matching user context */
+ if (dev->usrctxt != inode)
+ continue;
/* Stop kernel thread for multiple mode */
if (multiple_kthread_on && dev->pthread != NULL) {
kthread_stop(dev->pthread);
@@ -311,9 +314,10 @@ struct kni_net {
}
static int
-kni_ioctl_create(struct net *net, uint32_t ioctl_num,
+kni_ioctl_create(struct inode *inode, uint32_t ioctl_num,
unsigned long ioctl_param)
{
+ struct net *net = current->nsproxy->net_ns;
struct kni_net *knet = net_generic(net, kni_net_id);
int ret;
struct rte_kni_device_info dev_info;
@@ -374,7 +378,8 @@ struct kni_net {
dev_net_set(net_dev, net);
kni = netdev_priv(net_dev);
-
+
+ kni->usrctxt = inode;
kni->net_dev = net_dev;
kni->group_id = dev_info.group_id;
kni->core_id = dev_info.core_id;
@@ -493,9 +498,10 @@ struct kni_net {
}
static int
-kni_ioctl_release(struct net *net, uint32_t ioctl_num,
+kni_ioctl_release(struct inode *inode, uint32_t ioctl_num,
unsigned long ioctl_param)
{
+ struct net *net = current->nsproxy->net_ns;
struct kni_net *knet = net_generic(net, kni_net_id);
int ret = -EINVAL;
struct kni_dev *dev, *n;
@@ -516,6 +522,10 @@ struct kni_net {
down_write(&knet->kni_list_lock);
list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
+ /* only the owner user process can remove it*/
+ if (dev->usrctxt != inode)
+ continue;
+
if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) != 0)
continue;
@@ -540,7 +550,6 @@ struct kni_net {
kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param)
{
int ret = -EINVAL;
- struct net *net = current->nsproxy->net_ns;
pr_debug("IOCTL num=0x%0x param=0x%0lx\n", ioctl_num, ioctl_param);
@@ -552,10 +561,10 @@ struct kni_net {
/* For test only, not used */
break;
case _IOC_NR(RTE_KNI_IOCTL_CREATE):
- ret = kni_ioctl_create(net, ioctl_num, ioctl_param);
+ ret = kni_ioctl_create(inode, ioctl_num, ioctl_param);
break;
case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
- ret = kni_ioctl_release(net, ioctl_num, ioctl_param);
+ ret = kni_ioctl_release(inode, ioctl_num, ioctl_param);
break;
default:
pr_debug("IOCTL default\n");
--
1.9.1
next prev parent reply other threads:[~2017-05-03 11:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-03 11:21 [dpdk-dev] [RFC PATCH 1/5] kni: change and configure mac address Hemant Agrawal
2017-05-03 11:21 ` [dpdk-dev] [RFC PATCH 2/5] kni: add support for promisc mode set Hemant Agrawal
2017-05-03 11:21 ` [dpdk-dev] [RFC PATCH 3/5] kni: init and change request for mtu Hemant Agrawal
2017-05-03 11:21 ` [dpdk-dev] [RFC PATCH 4/5] kni: add support to get gso_size info Hemant Agrawal
2017-05-03 13:57 ` Alejandro Lucero
2017-05-05 11:43 ` Ferruh Yigit
2017-05-03 11:21 ` Hemant Agrawal [this message]
2017-05-05 13:08 ` [dpdk-dev] [RFC PATCH 5/5] kni: support multiple userspace process working with kni module Ferruh Yigit
2017-05-08 9:50 ` Hemant Agrawal
2017-05-05 11:28 ` [dpdk-dev] [RFC PATCH 1/5] kni: change and configure mac address Ferruh Yigit
2017-05-08 9:59 ` Hemant Agrawal
2017-11-28 22:31 ` Ferruh Yigit
2017-11-30 6:44 ` Hemant Agrawal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493810472-668-5-git-send-email-hemant.agrawal@nxp.com \
--to=hemant.agrawal@nxp.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).