Skip to contentSkip to conversation

nvme/046: add test for unprivileged passthrough

PATCH In review Kanchan Joshi 4 participants 6 messages Feb 9, 2023 – Feb 14, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20230209094631epcas5p436d4f54caa91ff6d258928bba76206de@epcas5p4.samsung.com

#1 lore raw

PATCH 1/1 nvme/046: add test for unprivileged passthrough

Ths creates a non-root user "blktest46", alters permissions for char-device node (/dev/ngX) and runs few passthrough commands. At the end of the test, user is deleted and permissions are reverted.

---
 tests/nvme/046     | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/046.out |  2 ++
 2 files changed, 57 insertions(+)
 create mode 100644 tests/nvme/046
 create mode 100644 tests/nvme/046.out
tests/nvme/046 new file +55 -0
new file mode 100644
index 0000000..40bda62
@@ -0,0 +1,55 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2023 Kanchan Joshi, Samsung Electronics
+# Test for unprivileged passthrough
+
+. tests/nvme/rc
+
+DESCRIPTION="basic test for unprivileged passthrough on /dev/ngX"
+QUICK=1
+
+requires() {
+	_nvme_requires
+	_have_fio
+}
+
+device_requires() {
+	_require_test_dev_is_nvme
+}
+
+test_device() {
+	echo "Running ${TEST_NAME}"
+	local ngdev=${TEST_DEV/nvme/ng}
+	local usr="blktest46"
+	local perm=$(stat -c "%a" $ngdev)
+	local nsid=$(_test_dev_nvme_nsid)
+
+	useradd -m $usr
+	chmod g+r,o+r "$ngdev"
+
+	if ! su $usr -c "nvme io-passthru ${ngdev} -o 2 -l 4096 \
+		-n $nsid -r" >> "${FULL}" 2>&1; then
+		echo "Error: io-passthru read failed"
+	fi
+
+	if su $usr -c "echo hello | nvme io-passthru ${ngdev} -o 1 -l 4096 \
+		-n $nsid -r" >> "${FULL}" 2>&1; then
+		echo "Error: io-passthru write passed (unexpected)"
+	fi
+
+	if ! su $usr -c "nvme id-ns ${ngdev}" >> "${FULL}" 2>&1; then
+		echo "Error: id-ns failed"
+	fi
+
+	if ! su $usr -c "nvme id-ctrl ${ngdev}" >> "${FULL}" 2>&1; then
+		echo "Error: id-ctrl failed"
+	fi
+
+	if su $usr -c "nvme ns-descs ${ngdev}" >> "${FULL}" 2>&1; then
+		echo "Error: ns-descs passed (unexpected)"
+	fi
+
+	echo "Test complete"
+	chmod  $perm "$ngdev"
+	userdel -r  $usr >> "${FULL}" 2>&1
+}
tests/nvme/046.out new file +2 -0
new file mode 100644
index 0000000..2b5fa6a
@@ -0,0 +1,2 @@
+Running nvme/046
+Test complete
Signature · 1 line
2.25.1
#2 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Kanchan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on hch-configfs/for-next]
[also build test WARNING on linus/master v6.2-rc7 next-20230209] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kanchan-Joshi/nvme-046-add-test-for-unprivileged-passthrough/20230209-174831
base:   git://git.infradead.org/users/hch/configfs.git for-next
patch link:    https://lore.kernel.org/r/20230209094541.248729-1-joshi.k%40samsung.com
patch subject: [PATCH blktests] nvme/046: add test for unprivileged passthrough

reproduce:
scripts/spdxcheck.py

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

spdxcheck warnings: (new ones prefixed by >>)
drivers/cpufreq/amd-pstate-ut.c: 1:28 Invalid License ID: GPL-1.0-or-later

>> tests/nvme/046: 2:27 Invalid License ID: GPL-3.0+
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#3 lore raw
In reply to Kanchan Joshi
Quoted 5 lines · Kanchan Joshi

Ths creates a non-root user "blktest46", alters permissions for char-device node (/dev/ngX) and runs few passthrough commands. At the end of the test, user is deleted and permissions are reverted.

Thanks for the patch. I guess this test case exercises nvme_cmd_allowed() in drivers/nvme/host/ioctl.c. The test contents look valid and good.

This test case adds and deletes a user. For every test case run, it creates and removes the user home directory and touches /etc files. It does not sound right for me. It changes system set up, and sudden test case stop will leave the user.

I suggest to ask blktests users to prepare the normal user and specify it to a config file variable (it can be named NORMAL_USER or something). I also suggest to add two new helper functions: _require_user() will check that the specified user is valid, and _run_user() will wrap the "su $NORMAL_USER -c" command line.

If you don't mind, I can create another patch for further discussion based on the suggestion above, and modify your patch to use the new helper functions.

Signature · 1 line
Shin'ichiro Kawasaki
#4 lore raw
Quoted 9 lines · Shinichiro Kawasaki
Quoted 5 lines · Kanchan Joshi

Ths creates a non-root user "blktest46", alters permissions for char-device node (/dev/ngX) and runs few passthrough commands. At the end of the test, user is deleted and permissions are reverted.

Thanks for the patch. I guess this test case exercises nvme_cmd_allowed() in drivers/nvme/host/ioctl.c.

Yes. Thanks for review.

Quoted 10 lines

The test contents look valid and good.

This test case adds and deletes a user. For every test case run, it creates and removes the user home directory and touches /etc files. It does not sound right for me. It changes system set up, and sudden test case stop will leave the user.

I suggest to ask blktests users to prepare the normal user and specify it to a config file variable (it can be named NORMAL_USER or something). I also suggest to add two new helper functions: _require_user() will check that the specified user is valid, and _run_user() will wrap the "su $NORMAL_USER -c" command line.

I was trying to make this automatic for blktests users. Script attempts cleanup always (regardless of test-failure). But yes, if any command gets stuck, cleanup won't happen. So what you mentioned - sounds fine to me.

Quoted 2 lines

If you don't mind, I can create another patch for further discussion based on the suggestion above, and modify your patch to use the new helper functions.

Sure. Please remove "_have_fio" line also in v2.

#5 lore raw
Quoted 1 line · Kanchan Joshi

On Fri, Feb 10, 2023 at 02:01:14AM +0000, Shinichiro Kawasaki wrote:

[...]

Quoted 3 lines
Quoted 2 lines

If you don't mind, I can create another patch for further discussion based on the suggestion above, and modify your patch to use the new helper functions.

Sure. Please remove "_have_fio" line also in v2.

Okay. I've sent out v2 [1]. Please check and confirm that it works for you.

FYI, I did a couple of more nit edits:

- No need to call _require_test_dev_is_nvme, since it is called from group_device_requires in tests/nvme/rc.
- Separated local variable declarations and initialization. ('make check' reported shellcheck complaints about it.)

[1] https://lore.kernel.org/linux-block/[email protected]/

Signature · 1 line
Shin'ichiro Kawasaki
#6 lore raw
Quoted 9 lines · Shinichiro Kawasaki
Quoted 1 line · Kanchan Joshi

On Fri, Feb 10, 2023 at 02:01:14AM +0000, Shinichiro Kawasaki wrote:

[...]

Quoted 3 lines
Quoted 2 lines

If you don't mind, I can create another patch for further discussion based on the suggestion above, and modify your patch to use the new helper functions.

Sure. Please remove "_have_fio" line also in v2.

Okay. I've sent out v2 [1]. Please check and confirm that it works for you.

Thanks. I am PTO for a few days; will come to it next week.