forked from Mellanox/dpdk-vhost-vfe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/vhost: import userspace vhost application
The vhost sample application demonstrates integration of the Intel(R) Data Plane Development Kit (Intel(R) DPDK) with the Linux KVM hypervisor by implementing the vhost-net offload API. The sample application performs simple packet switching between virtual machines based on Media Access Control (MAC) address or Virtual Local Area Network (VLAN) tag. The splitting of ethernet traffic from an external switch is performed in hardware by the Virtual Machine Device Queues (VMDQ) and Data Center Bridging (DCB) features of the Intel(R) 82599 10 Gigabit Ethernet Controller. Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
- Loading branch information
1 parent
de40804
commit 4796ad6
Showing
11 changed files
with
4,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# BSD LICENSE | ||
# | ||
# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in | ||
# the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Intel Corporation nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
ifeq ($(RTE_SDK),) | ||
$(error "Please define RTE_SDK environment variable") | ||
endif | ||
|
||
# Default target, can be overriden by command line or environment | ||
RTE_TARGET ?= x86_64-default-linuxapp-gcc | ||
|
||
include $(RTE_SDK)/mk/rte.vars.mk | ||
|
||
# binary name | ||
APP = vhost-switch | ||
|
||
# all source are stored in SRCS-y | ||
#SRCS-y := cusedrv.c loopback-userspace.c | ||
SRCS-y := main.c virtio-net.c vhost-net-cdev.c | ||
|
||
CFLAGS += -O2 -I/usr/local/include -D_FILE_OFFSET_BITS=64 -Wno-unused-parameter | ||
CFLAGS += $(WERROR_FLAGS) | ||
LDFLAGS += -lfuse | ||
|
||
include $(RTE_SDK)/mk/rte.extapp.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# BSD LICENSE | ||
# | ||
# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in | ||
# the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Intel Corporation nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
obj-m += eventfd_link.o | ||
|
||
|
||
all: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules | ||
|
||
clean: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/*- | ||
* * GPL LICENSE SUMMARY | ||
* * | ||
* * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. | ||
* * | ||
* * This program is free software; you can redistribute it and/or modify | ||
* * it under the terms of version 2 of the GNU General Public License as | ||
* * published by the Free Software Foundation. | ||
* * | ||
* * This program is distributed in the hope that it will be useful, but | ||
* * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* * General Public License for more details. | ||
* * | ||
* * You should have received a copy of the GNU General Public License | ||
* * along with this program; if not, write to the Free Software | ||
* * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
* * The full GNU General Public License is included in this distribution | ||
* * in the file called LICENSE.GPL. | ||
* * | ||
* * Contact Information: | ||
* * Intel Corporation | ||
* */ | ||
|
||
#include <linux/eventfd.h> | ||
#include <linux/miscdevice.h> | ||
#include <linux/module.h> | ||
#include <linux/moduleparam.h> | ||
#include <linux/rcupdate.h> | ||
#include <linux/file.h> | ||
#include <linux/slab.h> | ||
#include <linux/fs.h> | ||
#include <linux/mmu_context.h> | ||
#include <linux/sched.h> | ||
#include <asm/mmu_context.h> | ||
#include <linux/fdtable.h> | ||
|
||
#include "eventfd_link.h" | ||
|
||
|
||
/* | ||
* get_files_struct is copied from fs/file.c | ||
*/ | ||
struct files_struct * | ||
get_files_struct (struct task_struct *task) | ||
{ | ||
struct files_struct *files; | ||
|
||
task_lock (task); | ||
files = task->files; | ||
if (files) | ||
atomic_inc (&files->count); | ||
task_unlock (task); | ||
|
||
return files; | ||
} | ||
|
||
/* | ||
* put_files_struct is extracted from fs/file.c | ||
*/ | ||
void | ||
put_files_struct (struct files_struct *files) | ||
{ | ||
if (atomic_dec_and_test (&files->count)) | ||
{ | ||
BUG (); | ||
} | ||
} | ||
|
||
|
||
static long | ||
eventfd_link_ioctl (struct file *f, unsigned int ioctl, unsigned long arg) | ||
{ | ||
void __user *argp = (void __user *) arg; | ||
struct task_struct *task_target = NULL; | ||
struct file *file; | ||
struct files_struct *files; | ||
struct fdtable *fdt; | ||
struct eventfd_copy eventfd_copy; | ||
|
||
switch (ioctl) | ||
{ | ||
case EVENTFD_COPY: | ||
if (copy_from_user (&eventfd_copy, argp, sizeof (struct eventfd_copy))) | ||
return -EFAULT; | ||
|
||
/* | ||
* Find the task struct for the target pid | ||
*/ | ||
task_target = | ||
pid_task (find_vpid (eventfd_copy.target_pid), PIDTYPE_PID); | ||
if (task_target == NULL) | ||
{ | ||
printk (KERN_DEBUG "Failed to get mem ctx for target pid\n"); | ||
return -EFAULT; | ||
} | ||
|
||
files = get_files_struct (current); | ||
if (files == NULL) | ||
{ | ||
printk (KERN_DEBUG "Failed to get files struct\n"); | ||
return -EFAULT; | ||
} | ||
|
||
rcu_read_lock (); | ||
file = fcheck_files (files, eventfd_copy.source_fd); | ||
if (file) | ||
{ | ||
if (file->f_mode & FMODE_PATH | ||
|| !atomic_long_inc_not_zero (&file->f_count)) | ||
file = NULL; | ||
} | ||
rcu_read_unlock (); | ||
put_files_struct (files); | ||
|
||
if (file == NULL) | ||
{ | ||
printk (KERN_DEBUG "Failed to get file from source pid\n"); | ||
return 0; | ||
} | ||
|
||
/* | ||
* Release the existing eventfd in the source process | ||
*/ | ||
spin_lock (&files->file_lock); | ||
filp_close (file, files); | ||
fdt = files_fdtable (files); | ||
fdt->fd[eventfd_copy.source_fd] = NULL; | ||
spin_unlock (&files->file_lock); | ||
|
||
/* | ||
* Find the file struct associated with the target fd. | ||
*/ | ||
|
||
files = get_files_struct (task_target); | ||
if (files == NULL) | ||
{ | ||
printk (KERN_DEBUG "Failed to get files struct\n"); | ||
return -EFAULT; | ||
} | ||
|
||
rcu_read_lock (); | ||
file = fcheck_files (files, eventfd_copy.target_fd); | ||
if (file) | ||
{ | ||
if (file->f_mode & FMODE_PATH | ||
|| !atomic_long_inc_not_zero (&file->f_count)) | ||
file = NULL; | ||
} | ||
rcu_read_unlock (); | ||
put_files_struct (files); | ||
|
||
if (file == NULL) | ||
{ | ||
printk (KERN_DEBUG "Failed to get file from target pid\n"); | ||
return 0; | ||
} | ||
|
||
|
||
/* | ||
* Install the file struct from the target process into the | ||
* file desciptor of the source process, | ||
*/ | ||
|
||
fd_install (eventfd_copy.source_fd, file); | ||
|
||
return 0; | ||
|
||
default: | ||
return -ENOIOCTLCMD; | ||
} | ||
} | ||
|
||
static const struct file_operations eventfd_link_fops = { | ||
.owner = THIS_MODULE, | ||
.unlocked_ioctl = eventfd_link_ioctl, | ||
}; | ||
|
||
|
||
static struct miscdevice eventfd_link_misc = { | ||
.name = "eventfd-link", | ||
.fops = &eventfd_link_fops, | ||
}; | ||
|
||
static int __init | ||
eventfd_link_init (void) | ||
{ | ||
return misc_register (&eventfd_link_misc); | ||
} | ||
|
||
module_init (eventfd_link_init); | ||
|
||
static void __exit | ||
eventfd_link_exit (void) | ||
{ | ||
misc_deregister (&eventfd_link_misc); | ||
} | ||
|
||
module_exit (eventfd_link_exit); | ||
|
||
MODULE_VERSION ("0.0.1"); | ||
MODULE_LICENSE ("GPL v2"); | ||
MODULE_AUTHOR ("Anthony Fee"); | ||
MODULE_DESCRIPTION ("Link eventfd"); | ||
MODULE_ALIAS ("devname:eventfd-link"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*- | ||
* * This file is provided under a dual BSD/GPLv2 license. When using or | ||
* * redistributing this file, you may do so under either license. | ||
* * | ||
* * GPL LICENSE SUMMARY | ||
* * | ||
* * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. | ||
* * | ||
* * This program is free software; you can redistribute it and/or modify | ||
* * it under the terms of version 2 of the GNU General Public License as | ||
* * published by the Free Software Foundation. | ||
* * | ||
* * This program is distributed in the hope that it will be useful, but | ||
* * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* * General Public License for more details. | ||
* * | ||
* * You should have received a copy of the GNU General Public License | ||
* * along with this program; if not, write to the Free Software | ||
* * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
* * The full GNU General Public License is included in this distribution | ||
* * in the file called LICENSE.GPL. | ||
* * | ||
* * Contact Information: | ||
* * Intel Corporation | ||
* * | ||
* * BSD LICENSE | ||
* * | ||
* * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. | ||
* * All rights reserved. | ||
* * | ||
* * Redistribution and use in source and binary forms, with or without | ||
* * modification, are permitted provided that the following conditions | ||
* * are met: | ||
* * | ||
* * * Redistributions of source code must retain the above copyright | ||
* * notice, this list of conditions and the following disclaimer. | ||
* * * Redistributions in binary form must reproduce the above copyright | ||
* * notice, this list of conditions and the following disclaimer in | ||
* * the documentation and/or other materials provided with the | ||
* * distribution. | ||
* * * Neither the name of Intel Corporation nor the names of its | ||
* * contributors may be used to endorse or promote products derived | ||
* * from this software without specific prior written permission. | ||
* * | ||
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* * | ||
* */ | ||
|
||
#ifndef _EVENTFD_LINK_H_ | ||
#define _EVENTFD_LINK_H_ | ||
|
||
/* | ||
* ioctl to copy an fd entry in calling process to an fd in a target process | ||
*/ | ||
#define EVENTFD_COPY 1 | ||
|
||
/* | ||
* arguements for the EVENTFD_COPY ioctl | ||
*/ | ||
struct eventfd_copy { | ||
// fd in the target pid | ||
unsigned target_fd; | ||
// fd in the calling pid | ||
unsigned source_fd; | ||
// pid of the target pid | ||
pid_t target_pid; | ||
}; | ||
#endif /* _EVENTFD_LINK_H_ */ |
Oops, something went wrong.