From 7b25f04c432ec04a2423f8531e6ab05ab7735b7a Mon Sep 17 00:00:00 2001 From: Cunyin Chang Date: Wed, 6 Apr 2016 11:03:28 +0800 Subject: [PATCH] spdk: Enable vfio for non-privileged user. Change-Id: I72498ed727058e472b14c8ca8ee95b5858947afe Signed-off-by: Cunyin Chang --- scripts/setup.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 50573160c..68365ef69 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -32,6 +32,11 @@ function linux_bind_driver() { echo "$ven_dev_id" > "/sys/bus/pci/drivers/$driver_name/new_id" 2> /dev/null || true echo "$bdf" > "/sys/bus/pci/drivers/$driver_name/bind" 2> /dev/null || true + + iommu_group=$(basename $(readlink -f /sys/bus/pci/devices/$bdf/iommu_group)) + if [ -e "/dev/vfio/$iommu_group" ]; then + chown "$username" "/dev/vfio/$iommu_group" + fi } function configure_linux { @@ -69,6 +74,29 @@ function configure_linux { mount -t hugetlbfs nodev /mnt/huge fi echo "$NRHUGE" > /proc/sys/vm/nr_hugepages + + if [ "$driver_name" = "vfio-pci" ]; then + chown "$username" /dev/hugepages + + MEMLOCK_AMNT=`ulimit -l` + if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then + MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024` + echo "" + echo "Current user memlock limit: ${MEMLOCK_MB} MB" + echo "" + echo "This is the maximum amount of memory you will be" + echo "able to use with DPDK and VFIO if run as current user." + echo -n "To change this, please adjust limits.conf memlock " + echo "limit for current user." + + if [ $MEMLOCK_AMNT -lt 65536 ] ; then + echo "" + echo "## WARNING: memlock limit is less than 64MB" + echo -n "## DPDK with VFIO may not be able to initialize " + echo "if run as current user." + fi + fi + fi } function reset_linux { @@ -121,11 +149,22 @@ function reset_freebsd { NRHUGE=1024 -mode=$1 +username=$1 +mode=$2 + +if [ "$username" = "reset" -o "$username" = "config" ]; then + mode="$username" + username="" +fi + if [ "$mode" == "" ]; then mode="config" fi +if [ "$username" = "" ]; then + username=`logname` +fi + if [ `uname` = Linux ]; then if [ "$mode" == "config" ]; then configure_linux @@ -139,4 +178,3 @@ else reset_freebsd fi fi -