Skip to content

Commit 7369ab1

Browse files
authored
Add option to allow others instead of group in udev rules (#534)
1 parent 1e17dcb commit 7369ab1

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

sdk/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ $ sudo apt-get install build-essential
3838

3939
SDK supports granting access to FPGA resources and AFI management tools to users other than root. The SDK setup will create a group and make all the device resources members of this group. The user will be added to this group. Variables below help control this feature
4040
* AWS_FPGA_ALLOW_NON_ROOT when set, will turn on the feature.
41+
* AWS_FPGA_SDK_OTHERS when set, will allow all users to use FPGA, else only the group specified by AWS_FPGA_SDK_GROUP.
4142
* AWS_FPGA_SDK_GROUP specifies group that will have access to FPGA and AFI tools. The setup will create the group and add user to this group. User must switch or relogin to have this group membership effective. If unspecified, this will default to "fpgauser".
4243
* AWS_FPGA_SDK_OVERRIDE_GROUP specifies to add user to already existing group specified by AWS_FPGA_SDK_GROUP. If this is unset and AWS_FPGA_SDK_GROUP evaluates to an existing group, setup will fail.
4344

sdk/userspace/add_udev_rules.sh

+31-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ set -x
1919
source /tmp/sdk_root_env.exp
2020
set +x
2121
rm -f /tmp/sdk_root_env.exp
22+
23+
mkdir -p /opt/aws/bin
24+
25+
if [[ $AWS_FPGA_SDK_OTHERS ]]; then
26+
# Allow all users
27+
28+
# Make a script that will be run to change permissions everytime
29+
# udev rule for the DBDF is matched
30+
echo "Installing permission fix script for udev"
31+
cat >/opt/aws/bin/change-fpga-perm.sh<<EF
32+
#!/bin/bash
33+
set -x
34+
setperm () {
35+
chmod g=u \$1
36+
chmod a=u \$1
37+
}
38+
setfpgaperm () {
39+
for f in \$1/*; do
40+
setperm \$f;
41+
done
42+
}
43+
44+
devicePath=/sys/bus/pci/devices/\$1
45+
grep -q "0x058000" \$devicePath/class && setfpgaperm "\$devicePath"
46+
setperm /sys/bus/pci/rescan all
47+
EF
48+
49+
else
50+
# Allow group only
51+
2252
echo "Creating group ${AWS_FPGA_SDK_GROUP}"
2353
getent group ${AWS_FPGA_SDK_GROUP} >/dev/null 2>&1
2454
if [[ $? -eq 0 ]] ; then
@@ -49,7 +79,6 @@ fi
4979

5080
# Fail on any unsucessful command
5181
set -e
52-
mkdir -p /opt/aws/bin
5382
# Make a script that will be run to change permissions everytime
5483
# udev rule for the DBDF is matched
5584
echo "Installing permission fix script for udev"
@@ -76,6 +105,7 @@ devicePath=/sys/bus/pci/devices/\$1
76105
grep -q "0x058000" \$devicePath/class && setfpgaperm "\$devicePath"
77106
setperm /sys/bus/pci/rescan all
78107
EF
108+
fi
79109
chmod 544 /opt/aws/bin/change-fpga-perm.sh
80110

81111
DBDFs=`lspci -Dn | grep -Ew "1d0f:1042|1d0f:1041" | awk '{print $1}' | sed ':x;N;$!bx;s/\n/ /g'`

sdk_setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ source $script_dir/shared/bin/set_common_env_vars.sh
3333
sudo rm -f /tmp/sdk_root_env.exp
3434
typeset -f allow_non_root > /tmp/sdk_root_env.exp
3535
echo "export AWS_FPGA_SDK_GROUP=${AWS_FPGA_SDK_GROUP}" >> /tmp/sdk_root_env.exp
36+
echo "export AWS_FPGA_SDK_OTHERS=${AWS_FPGA_SDK_OTHERS}" >> /tmp/sdk_root_env.exp
3637
echo "export SDK_NON_ROOT_USER=${SDK_NON_ROOT_USER}" >> /tmp/sdk_root_env.exp
3738
echo "export AWS_FPGA_SDK_OVERRIDE_GROUP=${AWS_FPGA_SDK_OVERRIDE_GROUP}" >> /tmp/sdk_root_env.exp
3839
sudo chown root:root /tmp/sdk_root_env.exp

shared/bin/set_common_env_vars.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ unset HDK_SHELL_DIR
3434
unset HDK_SHELL_DESIGN_DIR
3535

3636
export -f allow_non_root
37+
export -f allow_others
3738

38-
if allow_non_root ; then
39+
if allow_non_root && allow_others ; then
3940
export AWS_FPGA_SDK_GROUP=${AWS_FPGA_SDK_GROUP:-"fpgauser"}
4041
export SDK_NON_ROOT_USER=$(whoami)
4142
info_msg "Allowing group ${AWS_FPGA_SDK_GROUP} access to FPGA management tools and resources"

shared/bin/set_common_functions.sh

+4
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,7 @@ function patch_AR73068 {
308308
function allow_non_root {
309309
[ ! -z ${AWS_FPGA_ALLOW_NON_ROOT} ]
310310
}
311+
312+
function allow_others {
313+
[ ! -z ${AWS_FPGA_SDK_OTHERS} ]
314+
}

0 commit comments

Comments
 (0)