filesetup: do not ask O_RDWR for read-only workload
A message that is not in the archive (sent off-list or not yet received): CGME20230203123513epcas5p4cb1961d7d1376bf39690f82de639d6f4@epcas5p4.samsung.com
PATCH 1/1 filesetup: do not ask O_RDWR for read-only workload
Use O_RDONLY flag when read is requested on char-type files.
---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1
$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
filesetup.c +1 -4
@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;if (is_std) f->fd =dup (STDIN_FILENO );
Signature · 1 line
2.25.1
Quoted 28 lines · Kanchan Joshi
Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0
filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;
This will break sg like interfaces, where a read is done by writing the command to the char device.
—
Jens Axboe
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 3 lines
—
Jens Axboe
Kanchan, does it work if you run fio with the --readonly option?
Vincent
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like FIO_RO_NEEDS_RW_OPEN or something, where the engine can tell us if it needs a writeable open even or a read-only workload.
Then generic_file_open() can use O_RDONLY for td_read(), except if the engine has FIO_RO_NEEDS_RW_OPEN set.
Signature · 1 line
Jens Axboe
Quoted 48 lines · Jens Axboe
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
Quoted 9 lines
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like
FIO_RO_NEEDS_RW_OPENor something, where the engine can tell us if it needs a writeable open even or a read-only workload.Then
generic_file_open()can useO_RDONLYfortd_read(), except if the engine hasFIO_RO_NEEDS_RW_OPENset.
Kanchan, can you try the diff below? It's also available at https://github.com/vincentkfu/fio/tree/rwopen
Vincent
engines/sg.c +1 -1
@@ -1428,7 +1428,7 @@ static struct ioengine_ops ioengine = { .open_file = fio_sgio_open, .close_file = fio_sgio_close, .get_file_size = fio_sgio_get_file_size, - .flags = FIO_SYNCIO | FIO_RAWIO, + .flags = FIO_SYNCIO | FIO_RAWIO | FIO_RO_NEEDS_RW_OPEN, .options = options, .option_struct_size = sizeof(struct sg_options) };
filesetup.c +1 -1
@@ -768,7 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) +if (td_ioengine_flagged (td,FIO_RO_NEEDS_RW_OPEN ) && !read_only) flags |=O_RDWR ;else flags |=O_RDONLY ;
ioengines.h +0 -0
@@ -89,6 +89,8 @@ enum fio_ioengine_flags { = 1 << 16, /* async ioengine with commit function that sets
issue_time */
FIO_SKIPPABLE_IOMEM_ALLOC
= 1 << 17, /* skip iomem_alloc & iomem_free if job sets mem/iomem */
+ FIO_RO_NEEDS_RW_OPEN
+ = 1 << 18, /* open files in rw mode even if we have a read job */
};
/*
Quoted 31 lines · Vincent Fu
engines/sg.c +1
-1@@ -1428,7 +1428,7 @@ static struct ioengine_ops ioengine = { .open_file = fio_sgio_open, .close_file = fio_sgio_close, .get_file_size = fio_sgio_get_file_size, - .flags = FIO_SYNCIO | FIO_RAWIO, + .flags = FIO_SYNCIO | FIO_RAWIO | FIO_RO_NEEDS_RW_OPEN, .options = options, .option_struct_size = sizeof(struct sg_options) };filesetup.c +1
-1@@ -768,7 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) +if (td_ioengine_flagged (td,FIO_RO_NEEDS_RW_OPEN ) && !read_only) flags |=O_RDWR ;else flags |=O_RDONLY ;ioengines.h +0
-0
ioengines.h enum fio_ioengine_flags { · line 96
Quoted 8 lines
ioengines.h +2
-0@@ -89,6 +89,8 @@ enum fio_ioengine_flags { =1 <<16 ,/* async ioengine with commit function that sets issue_time */ FIO_SKIPPABLE_IOMEM_ALLOC =1 <<17 ,/* skip iomem_alloc & iomem_free if job sets mem/iomem */ +FIO_RO_NEEDS_RW_OPEN + = 1 << 18, /* open files in rw mode even if we have a read job */ };/*
Looks good to me.
Signature · 1 line
Jens Axboe
Quoted 55 lines · Vincent Fu
Quoted 54 lines · Jens Axboe
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like
FIO_RO_NEEDS_RW_OPENor something, where the engine can tell us if it needs a writeable open even or a read-only workload.
Quoted 5 lines
Quoted 3 lines
Then
generic_file_open()can useO_RDONLYfortd_read(), except if the engine hasFIO_RO_NEEDS_RW_OPENset.Kanchan, can you try the diff below? It's also available at https://protect2.fireeye.com/v1/url?k=37173803-566c928b-3716b34c-74fe4860018a-aac6167af74310c3&q=1&e=3e678cf7-7d3f-487a-8a94-a9f0b41ca778&u=https%3A%2F%2Fgithub.com%2Fvincentkfu%2Ffio%2Ftree%2Frwopen
Tried, this works, thanks!
The patch looks good. Seems this flag can be added to libzbc engine too. That also treats the the char-type open in the same way.
Quoted 60 lines · Kanchan Joshi
Quoted 59 lines · Vincent Fu
Quoted 57 lines · Jens Axboe
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like
FIO_RO_NEEDS_RW_OPENor something, where the engine can tell us if it needs a writeable open even or a read-only workload.Then
generic_file_open()can useO_RDONLYfortd_read(), except if the engine hasFIO_RO_NEEDS_RW_OPENset.
Quoted 5 lines
Quoted 1 line
Kanchan, can you try the diff below? It's also available at https://protect2.fireeye.com/v1/url?k=37173803-566c928b-3716b34c-74fe4860018a-aac6167af74310c3&q=1&e=3e678cf7-7d3f-487a-8a94-a9f0b41ca778&u=https%3A%2F%2Fgithub.com%2Fvincentkfu%2Ffio%2Ftree%2Frwopen
Tried, this works, thanks!
The patch looks good. Seems this flag can be added to libzbc engine too. That also treats the the char-type open in the same way.
Thanks for testing - I've added it for libzbc as well.
Signature · 1 line
Jens Axboe
Quoted 61 lines · Jens Axboe
Quoted 60 lines · Kanchan Joshi
Quoted 59 lines · Vincent Fu
Quoted 57 lines · Jens Axboe
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like
FIO_RO_NEEDS_RW_OPENor something, where the engine can tell us if it needs a writeable open even or a read-only workload.Then
generic_file_open()can useO_RDONLYfortd_read(), except if the engine hasFIO_RO_NEEDS_RW_OPENset.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Kanchan, can you try the diff below? It's also available at https://protect2.fireeye.com/v1/url?k=37173803-566c928b-3716b34c-74fe4860018a-aac6167af74310c3&q=1&e=3e678cf7-7d3f-487a-8a94-a9f0b41ca778&u=https%3A%2F%2Fgithub.com%2Fvincentkfu%2Ffio%2Ftree%2Frwopen
Tried, this works, thanks!
The patch looks good. Seems this flag can be added to libzbc engine too. That also treats the the char-type open in the same way.Thanks for testing - I've added it for libzbc as well.
The new flag only affects generic_file_open() but the libzbc ioengine has its own file open function. So the flag has no effect.
Moreover libzbc uses the SG_IO ioctl even for character devices. So the code in libzbc_open_dev() (copied from generic_file_open) that opens character devices with O_RDWR is actually unnecessary.
I've committed some patches to tidy things up.
Vincent
Quoted 68 lines · Vincent Fu
Quoted 67 lines · Jens Axboe
Quoted 65 lines · Kanchan Joshi
Quoted 55 lines · Vincent Fu
Quoted 54 lines · Jens Axboe
Quoted 41 lines · Vincent Fu
Quoted 40 lines · Jens Axboe
Quoted 28 lines · Kanchan Joshi
?Use
O_RDONLYflag when read is requested on char-type files.Signed-off-by Kanchan Joshi <[email protected]>---
Before this patch: unexpected permission-denial for unprivileged-user.
$ ls -l /dev/ng0n1 cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1$ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 fio-3.33-71-g7d7a Starting 1 process fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), error=Permission denied
filesetup.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)filesetup.c +0
-0filesetup.c open_again: · line 771
Quoted 8 lines
filesetup.c +1
-4@@ -768,10 +768,7 @@ open_again:else from_hash =file_lookup_open (f, flags); }else if (td_read (td)) { -if (f->filetype ==FIO_TYPE_CHAR && !read_only) - flags |=O_RDWR ; -else - flags |=O_RDONLY ; + flags |=O_RDONLY ;This will break sg like interfaces, where a read is done by writing the command to the char device.
Quoted 5 lines
Quoted 3 lines
?
Jens AxboeKanchan, does it work if you run fio with the --readonly option?
I think we should just make it work. Conceptually, the patch is obviously fine, it just happens to break some oddball cases like sg/bsg. But maybe we just add a fio ioengine flag for that, like
FIO_RO_NEEDS_RW_OPENor something, where the engine can tell us if it needs a writeable open even or a read-only workload.Quoted 5 lines
Quoted 3 lines
Then
generic_file_open()can useO_RDONLYfortd_read(), except if the engine hasFIO_RO_NEEDS_RW_OPENset.Kanchan, can you try the diff below? It's also available at https://protect2.fireeye.com/v1/url?k=37173803-566c928b-3716b34c-74fe4860018a-aac6167af74310c3&q=1&e=3e678cf7-7d3f-487a-8a94-a9f0b41ca778&u=https%3A%2F%2Fgithub.com%2Fvincentkfu%2Ffio%2Ftree%2Frwopen
Tried, this works, thanks!
The patch looks good. Seems this flag can be added to libzbc engine too. That also treats the the char-type open in the same way.
Quoted 5 lines
Quoted 2 lines
Thanks for testing - I've added it for libzbc as well.
The new flag only affects
generic_file_open()but the libzbc ioengine has its own file open function. So the flag has no effect.
That's a good point, not sure how I missed that when I explicitly checked sg for it last week...
Quoted 5 lines
Moreover libzbc uses the
SG_IOioctl even for character devices. So the code inlibzbc_open_dev()(copied fromgeneric_file_open) that opens character devices withO_RDWRis actually unnecessary.I've committed some patches to tidy things up.
Thanks!
Signature · 1 line
Jens Axboe