aboutsummaryrefslogtreecommitdiffstats
diff options
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-11-23 08:47:23 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-11-23 08:47:23 +0100
commit5a4549f7ebf22787b2a76908ba90598e453d4a15 (patch)
treeae3fc6cb130c4944f1b7bf7790e036fba779e606
parent42e4dab3dbfbf82344ceacacdc039d79feca67a5 (diff)
downloadpatches-5a4549f7ebf22787b2a76908ba90598e453d4a15.tar.gz
readfile patches updated
-rw-r--r--0001-readfile-implement-readfile-syscall.patch13
-rw-r--r--0002-arch-wire-up-the-readfile-syscall.patch215
-rw-r--r--0003-selftests-add-readfile-2-selftests.patch239
-rw-r--r--0004-readfile.2-new-page-describing-readfile-2.patch (renamed from 0004-readfile.2.patch)109
-rw-r--r--series2
5 files changed, 325 insertions, 253 deletions
diff --git a/0001-readfile-implement-readfile-syscall.patch b/0001-readfile-implement-readfile-syscall.patch
index 6c90542e83401b..bf966a945243fd 100644
--- a/0001-readfile-implement-readfile-syscall.patch
+++ b/0001-readfile-implement-readfile-syscall.patch
@@ -1,4 +1,4 @@
-From 654540d453a03efc0fe7fc0e0d155981051b10c4 Mon Sep 17 00:00:00 2001
+From 0b91def003b129b2f80bb374ad0a5aaf391bff03 Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Sun, 24 May 2020 12:37:15 +0200
Subject: [PATCH 1/4] readfile: implement readfile syscall
@@ -15,12 +15,14 @@ overhead.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
- fs/open.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
+ fs/open.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
+diff --git a/fs/open.c b/fs/open.c
+index 9af548fb841b..b411c2b3ebd6 100644
--- a/fs/open.c
+++ b/fs/open.c
-@@ -1381,3 +1381,53 @@ int stream_open(struct inode *inode, str
+@@ -1381,3 +1381,53 @@ int stream_open(struct inode *inode, struct file *filp)
}
EXPORT_SYMBOL(stream_open);
@@ -53,7 +55,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ int retval;
+
+ /* only accept a small subset of O_ flags that make sense */
-+ if ((flags | O_NOFOLLOW | O_NOATIME) != flags)
++ if ((flags & (O_NOFOLLOW | O_NOATIME)) != flags)
+ return -EINVAL;
+
+ /* add some needed flags to be able to open the file properly */
@@ -74,3 +76,6 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+ return retval;
+}
+--
+2.29.2
+
diff --git a/0002-arch-wire-up-the-readfile-syscall.patch b/0002-arch-wire-up-the-readfile-syscall.patch
index 35f10475143f89..d1b4a3b933d9b2 100644
--- a/0002-arch-wire-up-the-readfile-syscall.patch
+++ b/0002-arch-wire-up-the-readfile-syscall.patch
@@ -1,4 +1,4 @@
-From 4135ebc2076a72c3ad10d0102e8ebc82140abf8d Mon Sep 17 00:00:00 2001
+From 39b066fa7c6b33fffe445e2201f19a6740b4fbc2 Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Sun, 24 May 2020 12:36:21 +0200
Subject: [PATCH 2/4] arch: wire up the readfile syscall
@@ -7,168 +7,192 @@ This wires up the readfile syscall for all architectures
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
- arch/alpha/kernel/syscalls/syscall.tbl | 1 +
- arch/arm/tools/syscall.tbl | 1 +
- arch/arm64/include/asm/unistd.h | 2 +-
- arch/arm64/include/asm/unistd32.h | 2 ++
- arch/ia64/kernel/syscalls/syscall.tbl | 1 +
- arch/m68k/kernel/syscalls/syscall.tbl | 1 +
- arch/microblaze/kernel/syscalls/syscall.tbl | 1 +
- arch/mips/kernel/syscalls/syscall_n32.tbl | 1 +
- arch/mips/kernel/syscalls/syscall_n64.tbl | 1 +
- arch/mips/kernel/syscalls/syscall_o32.tbl | 1 +
- arch/parisc/kernel/syscalls/syscall.tbl | 1 +
- arch/powerpc/kernel/syscalls/syscall.tbl | 1 +
- arch/s390/kernel/syscalls/syscall.tbl | 1 +
- arch/sh/kernel/syscalls/syscall.tbl | 1 +
- arch/sparc/kernel/syscalls/syscall.tbl | 1 +
- arch/x86/entry/syscalls/syscall_32.tbl | 1 +
- arch/x86/entry/syscalls/syscall_64.tbl | 1 +
- arch/xtensa/kernel/syscalls/syscall.tbl | 1 +
- include/linux/syscalls.h | 2 ++
- include/uapi/asm-generic/unistd.h | 4 +++-
- 20 files changed, 24 insertions(+), 2 deletions(-)
+ arch/alpha/kernel/syscalls/syscall.tbl | 1 +
+ arch/arm/tools/syscall.tbl | 1 +
+ arch/arm64/include/asm/unistd32.h | 2 ++
+ arch/ia64/kernel/syscalls/syscall.tbl | 1 +
+ arch/m68k/kernel/syscalls/syscall.tbl | 1 +
+ arch/microblaze/kernel/syscalls/syscall.tbl | 1 +
+ arch/mips/kernel/syscalls/syscall_n32.tbl | 1 +
+ arch/mips/kernel/syscalls/syscall_n64.tbl | 1 +
+ arch/mips/kernel/syscalls/syscall_o32.tbl | 1 +
+ arch/parisc/kernel/syscalls/syscall.tbl | 1 +
+ arch/powerpc/kernel/syscalls/syscall.tbl | 1 +
+ arch/s390/kernel/syscalls/syscall.tbl | 1 +
+ arch/sh/kernel/syscalls/syscall.tbl | 1 +
+ arch/sparc/kernel/syscalls/syscall.tbl | 1 +
+ arch/x86/entry/syscalls/syscall_32.tbl | 1 +
+ arch/x86/entry/syscalls/syscall_64.tbl | 1 +
+ arch/xtensa/kernel/syscalls/syscall.tbl | 1 +
+ include/linux/syscalls.h | 2 ++
+ include/uapi/asm-generic/unistd.h | 4 +++-
+ 19 files changed, 23 insertions(+), 1 deletion(-)
+diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl
+index ee7b01bb7346..9665012486e7 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
-@@ -479,3 +479,4 @@
- 547 common openat2 sys_openat2
+@@ -480,3 +480,4 @@
548 common pidfd_getfd sys_pidfd_getfd
549 common faccessat2 sys_faccessat2
-+550 common readfile sys_readfile
+ 550 common process_madvise sys_process_madvise
++551 common readfile sys_readfile
+diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
+index d056a548358e..88acc17373bb 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
-@@ -453,3 +453,4 @@
- 437 common openat2 sys_openat2
+@@ -454,3 +454,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
---- a/arch/arm64/include/asm/unistd.h
-+++ b/arch/arm64/include/asm/unistd.h
-@@ -38,7 +38,7 @@
- #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
- #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800)
-
--#define __NR_compat_syscalls 440
-+#define __NR_compat_syscalls 441
- #endif
-
- #define __ARCH_WANT_SYS_CLONE
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h
+index 107f08e03b9f..b92b3e3fac18 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
-@@ -887,6 +887,8 @@ __SYSCALL(__NR_openat2, sys_openat2)
- __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
- #define __NR_faccessat2 439
+@@ -889,6 +889,8 @@ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
__SYSCALL(__NR_faccessat2, sys_faccessat2)
-+#define __NR_readfile 440
+ #define __NR_process_madvise 440
+ __SYSCALL(__NR_process_madvise, sys_process_madvise)
++#define __NR_readfile 441
+__SYSCALL(__NR_readfile, sys_readfile)
/*
* Please add new compat syscalls above this comment and update
+diff --git a/arch/ia64/kernel/syscalls/syscall.tbl b/arch/ia64/kernel/syscalls/syscall.tbl
+index b96ed8b8a508..ad5e62125858 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
-@@ -360,3 +360,4 @@
- 437 common openat2 sys_openat2
+@@ -361,3 +361,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl
+index 625fb6d32842..fbe539d66af9 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
-@@ -439,3 +439,4 @@
- 437 common openat2 sys_openat2
+@@ -440,3 +440,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/microblaze/kernel/syscalls/syscall.tbl b/arch/microblaze/kernel/syscalls/syscall.tbl
+index aae729c95cf9..e0a7084f2128 100644
--- a/arch/microblaze/kernel/syscalls/syscall.tbl
+++ b/arch/microblaze/kernel/syscalls/syscall.tbl
-@@ -445,3 +445,4 @@
- 437 common openat2 sys_openat2
+@@ -446,3 +446,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
+index 32817c954435..9e3bbd44e277 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
-@@ -378,3 +378,4 @@
- 437 n32 openat2 sys_openat2
+@@ -379,3 +379,4 @@
438 n32 pidfd_getfd sys_pidfd_getfd
439 n32 faccessat2 sys_faccessat2
-+440 n32 readfile sys_readfile
+ 440 n32 process_madvise sys_process_madvise
++441 n32 readfile sys_readfile
+diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
+index 9e4ea3c31b1c..efa890ff2d6d 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
-@@ -354,3 +354,4 @@
- 437 n64 openat2 sys_openat2
+@@ -355,3 +355,4 @@
438 n64 pidfd_getfd sys_pidfd_getfd
439 n64 faccessat2 sys_faccessat2
-+440 n64 readfile sys_readfile
+ 440 n64 process_madvise sys_process_madvise
++441 n64 readfile sys_readfile
+diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
+index 29f5f28cf5ce..68b48d230657 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
-@@ -427,3 +427,4 @@
- 437 o32 openat2 sys_openat2
+@@ -428,3 +428,4 @@
438 o32 pidfd_getfd sys_pidfd_getfd
439 o32 faccessat2 sys_faccessat2
-+440 o32 readfile sys_readfile
+ 440 o32 process_madvise sys_process_madvise
++441 o32 readfile sys_readfile
+diff --git a/arch/parisc/kernel/syscalls/syscall.tbl b/arch/parisc/kernel/syscalls/syscall.tbl
+index f375ea528e59..ea0b323b9af3 100644
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
-@@ -437,3 +437,4 @@
- 437 common openat2 sys_openat2
+@@ -438,3 +438,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl
+index 1275daec7fec..15ace3e8e99c 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
-@@ -529,3 +529,4 @@
- 437 common openat2 sys_openat2
+@@ -530,3 +530,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl
+index 28c168000483..7e80ef92ef96 100644
--- a/arch/s390/kernel/syscalls/syscall.tbl
+++ b/arch/s390/kernel/syscalls/syscall.tbl
-@@ -442,3 +442,4 @@
- 437 common openat2 sys_openat2 sys_openat2
+@@ -443,3 +443,4 @@
438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2 sys_faccessat2
-+440 common readfile sys_readfile sys_readfile
+ 440 common process_madvise sys_process_madvise sys_process_madvise
++441 common readfile sys_readfile sys_readfile
+diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl
+index 783738448ff5..56a6b3030733 100644
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
-@@ -442,3 +442,4 @@
- 437 common openat2 sys_openat2
+@@ -443,3 +443,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl
+index 78160260991b..a14c1690fae5 100644
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
-@@ -485,3 +485,4 @@
- 437 common openat2 sys_openat2
+@@ -486,3 +486,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
+index 0d0667a9fbd7..c50df8220baf 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
-@@ -444,3 +444,4 @@
- 437 i386 openat2 sys_openat2
+@@ -445,3 +445,4 @@
438 i386 pidfd_getfd sys_pidfd_getfd
439 i386 faccessat2 sys_faccessat2
-+440 i386 readfile sys_readfile
+ 440 i386 process_madvise sys_process_madvise
++441 i386 readfile sys_readfile
+diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
+index 379819244b91..c2d57fca0bd8 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
-@@ -361,6 +361,7 @@
- 437 common openat2 sys_openat2
+@@ -362,6 +362,7 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
#
- # x32-specific system call numbers start at 512 to avoid cache impact
+ # Due to a historical design error, certain syscalls are numbered differently
+diff --git a/arch/xtensa/kernel/syscalls/syscall.tbl b/arch/xtensa/kernel/syscalls/syscall.tbl
+index b070f272995d..db4a5e18ecc8 100644
--- a/arch/xtensa/kernel/syscalls/syscall.tbl
+++ b/arch/xtensa/kernel/syscalls/syscall.tbl
-@@ -410,3 +410,4 @@
- 437 common openat2 sys_openat2
+@@ -411,3 +411,4 @@
438 common pidfd_getfd sys_pidfd_getfd
439 common faccessat2 sys_faccessat2
-+440 common readfile sys_readfile
+ 440 common process_madvise sys_process_madvise
++441 common readfile sys_readfile
+diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
+index 37bea07c12f2..653d3a3ad1c4 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
-@@ -1006,6 +1006,8 @@ asmlinkage long sys_pidfd_send_signal(in
+@@ -1008,6 +1008,8 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
siginfo_t __user *info,
unsigned int flags);
asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
@@ -177,18 +201,23 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
/*
* Architecture-specific system calls
+diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
+index 2056318988f7..7a0bee36e0a7 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
-@@ -859,9 +859,11 @@ __SYSCALL(__NR_openat2, sys_openat2)
- __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
- #define __NR_faccessat2 439
+@@ -859,9 +859,11 @@ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
__SYSCALL(__NR_faccessat2, sys_faccessat2)
-+#define __NR_readfile 440
+ #define __NR_process_madvise 440
+ __SYSCALL(__NR_process_madvise, sys_process_madvise)
++#define __NR_readfile 441
+__SYSCALL(__NR_readfile, sys_readfile)
#undef __NR_syscalls
--#define __NR_syscalls 440
-+#define __NR_syscalls 441
+-#define __NR_syscalls 441
++#define __NR_syscalls 442
/*
* 32 bit systems traditionally used different
+--
+2.29.2
+
diff --git a/0003-selftests-add-readfile-2-selftests.patch b/0003-selftests-add-readfile-2-selftests.patch
index daf8a5b5b6845c..ae8e89b2a020a3 100644
--- a/0003-selftests-add-readfile-2-selftests.patch
+++ b/0003-selftests-add-readfile-2-selftests.patch
@@ -1,4 +1,4 @@
-From 8928abbad99c7d3750695998e5fa7ba144da3300 Mon Sep 17 00:00:00 2001
+From 3e95be22367650a45fcbfd8c8da95e8a6db7a8f7 Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Sun, 8 Mar 2020 09:54:45 +0100
Subject: [PATCH 3/4] selftests: add readfile(2) selftests
@@ -10,17 +10,19 @@ instead of using open()/read()/close().
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
- tools/testing/selftests/Makefile | 1
- tools/testing/selftests/readfile/.gitignore | 3
- tools/testing/selftests/readfile/Makefile | 7
- tools/testing/selftests/readfile/readfile.c | 285 ++++++++++++++++++++++
- tools/testing/selftests/readfile/readfile_speed.c | 221 +++++++++++++++++
- 5 files changed, 517 insertions(+)
+ tools/testing/selftests/Makefile | 1 +
+ tools/testing/selftests/readfile/.gitignore | 3 +
+ tools/testing/selftests/readfile/Makefile | 7 +
+ tools/testing/selftests/readfile/readfile.c | 285 +++++++++++++++++
+ .../selftests/readfile/readfile_speed.c | 301 ++++++++++++++++++
+ 5 files changed, 597 insertions(+)
create mode 100644 tools/testing/selftests/readfile/.gitignore
create mode 100644 tools/testing/selftests/readfile/Makefile
create mode 100644 tools/testing/selftests/readfile/readfile.c
create mode 100644 tools/testing/selftests/readfile/readfile_speed.c
+diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
+index d9c283503159..0788bf87408f 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -49,6 +49,7 @@ TARGETS += ptrace
@@ -31,12 +33,18 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
TARGETS += seccomp
TARGETS += sigaltstack
TARGETS += size
+diff --git a/tools/testing/selftests/readfile/.gitignore b/tools/testing/selftests/readfile/.gitignore
+new file mode 100644
+index 000000000000..f0e758d437e4
--- /dev/null
+++ b/tools/testing/selftests/readfile/.gitignore
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+readfile
+readfile_speed
+diff --git a/tools/testing/selftests/readfile/Makefile b/tools/testing/selftests/readfile/Makefile
+new file mode 100644
+index 000000000000..1bf1bdec40f8
--- /dev/null
+++ b/tools/testing/selftests/readfile/Makefile
@@ -0,0 +1,7 @@
@@ -47,6 +55,9 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+TEST_GEN_PROGS := readfile readfile_speed
+
+include ../lib.mk
+diff --git a/tools/testing/selftests/readfile/readfile.c b/tools/testing/selftests/readfile/readfile.c
+new file mode 100644
+index 000000000000..ddaf57896b2f
--- /dev/null
+++ b/tools/testing/selftests/readfile/readfile.c
@@ -0,0 +1,285 @@
@@ -74,7 +85,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+//#define __NR_readfile -1
+//#endif
+
-+#define __NR_readfile 440
++#define __NR_readfile 441
+
+#define TEST_FILE1 "/sys/devices/system/cpu/vulnerabilities/meltdown"
+#define TEST_FILE2 "/sys/devices/system/cpu/vulnerabilities/spectre_v1"
@@ -335,39 +346,58 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ return ksft_exit_pass();
+}
+
+diff --git a/tools/testing/selftests/readfile/readfile_speed.c b/tools/testing/selftests/readfile/readfile_speed.c
+new file mode 100644
+index 000000000000..a9c6badf67a2
--- /dev/null
+++ b/tools/testing/selftests/readfile/readfile_speed.c
-@@ -0,0 +1,221 @@
+@@ -0,0 +1,301 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ * Copyright (c) 2020 The Linux Foundation
+ *
+ * Tiny test program to try to benchmark the speed of the readfile syscall vs.
-+ * the open/read/close sequence it replaces.
++ * the open/read/close sequence it can replace.
+ */
+#define _GNU_SOURCE
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <sys/syscall.h>
-+#include <sys/types.h>
-+#include <sys/stat.h>
+#include <dirent.h>
++#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
++#include <stdarg.h>
++#include <stdio.h>
++#include <stdlib.h>
+#include <string.h>
++#include <sys/stat.h>
++#include <sys/syscall.h>
++#include <sys/types.h>
+#include <syscall.h>
-+#include <errno.h>
++#include <time.h>
+#include <unistd.h>
-+#include <stdarg.h>
+
++/* Default test file if no one wants to pick something else */
++#define DEFAULT_TEST_FILE "/sys/devices/system/cpu/vulnerabilities/meltdown"
++
++#define DEFAULT_TEST_LOOPS 1000
++
++#define DEFAULT_TEST_TYPE "both"
++
++/* Max number of bytes that will be read from the file */
++#define TEST_BUFFER_SIZE 10000
++static unsigned char test_buffer[TEST_BUFFER_SIZE];
++
++enum test_type {
++ TEST_READFILE,
++ TEST_OPENREADCLOSE,
++ TEST_BOTH,
++};
++
++/* Find the readfile syscall number */
+//#ifndef __NR_readfile
+//#define __NR_readfile -1
+//#endif
-+
-+#define __NR_readfile 440
-+
-+#define TEST_FILE "/sys/devices/system/cpu/vulnerabilities/meltdown"
++#define __NR_readfile 441
+
+static int sys_readfile(int fd, const char *filename, unsigned char *buffer,
+ size_t bufsize, int flags)
@@ -375,6 +405,40 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ return syscall(__NR_readfile, fd, filename, buffer, bufsize, flags);
+}
+
++/* Test that readfile() is even in the running kernel or not. */
++static void test_readfile_supported(void)
++{
++ const char *proc_map = "/proc/self/maps";
++ unsigned char buffer[10];
++ int retval;
++
++ if (__NR_readfile < 0) {
++ fprintf(stderr,
++ "readfile() syscall is not defined for the kernel this test was built against.\n");
++ exit(1);
++ }
++
++ /*
++ * Do a simple test to see if the syscall really is present in the
++ * running kernel
++ */
++ retval = sys_readfile(0, proc_map, &buffer[0], sizeof(buffer), 0);
++ if (retval == -1) {
++ fprintf(stderr,
++ "readfile() syscall not present on running kernel.\n");
++ exit(1);
++ }
++}
++
++static inline long long get_time_ns(void)
++{
++ struct timespec t;
++
++ clock_gettime(CLOCK_MONOTONIC, &t);
++
++ return (long long)t.tv_sec * 1000000000 + t.tv_nsec;
++}
++
+/* taken from all-io.h from util-linux repo */
+static inline ssize_t read_all(int fd, unsigned char *buf, size_t count)
+{
@@ -382,7 +446,6 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ ssize_t c = 0;
+ int tries = 0;
+
-+ //memset(buf, 0, count);
+ while (count > 0) {
+ ret = read(fd, buf, count);
+ if (ret <= 0) {
@@ -422,54 +485,80 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ return count;
+}
+
-+enum test_type {
-+ READFILE,
-+ OPENREADCLOSE,
-+};
-+
-+static int do_read_file_test(int loops, enum test_type test_type,
-+ const char *filename,
-+ unsigned char *buffer, size_t bufsize)
++static int run_test(enum test_type test_type, const char *filename)
+{
-+ char *test;
-+ int retval;
-+ int i;
-+
+ switch (test_type) {
-+ case READFILE:
-+ test = "readfile";
-+ break;
++ case TEST_READFILE:
++ return sys_readfile(0, filename, &test_buffer[0],
++ TEST_BUFFER_SIZE, O_RDONLY);
+
-+ case OPENREADCLOSE:
-+ test = "open/read/close";
-+ break;
++ case TEST_OPENREADCLOSE:
++ return openreadclose(filename, &test_buffer[0],
++ TEST_BUFFER_SIZE);
+ default:
-+ fprintf(stderr, "wrong test type");
-+ return -1;
++ return -EINVAL;
+ }
++}
++
++static const char * const test_names[] = {
++ [TEST_READFILE] = "readfile",
++ [TEST_OPENREADCLOSE] = "open/read/close",
++};
++
++static int run_test_loop(int loops, enum test_type test_type,
++ const char *filename)
++{
++ long long time_start;
++ long long time_end;
++ long long time_elapsed;
++ int retval = 0;
++ int i;
+
+ fprintf(stdout,
+ "Running %s test on file %s for %d loops...\n",
-+ test, filename, loops);
++ test_names[test_type], filename, loops);
++
++ /* Fill the cache with one run of the read first */
++ retval = run_test(test_type, filename);
++ if (retval < 0) {
++ fprintf(stderr,
++ "test %s was unable to run with error %d\n",
++ test_names[test_type], retval);
++ return retval;
++ }
++
++ time_start = get_time_ns();
+
+ for (i = 0; i < loops; ++i) {
-+ switch (test_type) {
-+ case READFILE:
-+ retval = sys_readfile(0, filename, buffer, bufsize, O_RDONLY);
-+ break;
++ retval = run_test(test_type, filename);
+
-+ case OPENREADCLOSE:
-+ retval = openreadclose(filename, buffer, bufsize);
-+ break;
-+ }
+ if (retval < 0) {
+ fprintf(stderr,
+ "test failed on loop %d with error %d\n",
+ i, retval);
-+ return retval;
++ break;
+ }
+ }
-+ return 0;
++ time_end = get_time_ns();
++
++ time_elapsed = time_end - time_start;
++
++ fprintf(stdout, "Took %lld ns\n", time_elapsed);
++
++ return retval;
++}
++
++static int do_read_file_test(int loops, enum test_type test_type,
++ const char *filename)
++{
++ int retval;
++
++ if (test_type == TEST_BOTH) {
++ retval = do_read_file_test(loops, TEST_READFILE, filename);
++ retval = do_read_file_test(loops, TEST_OPENREADCLOSE, filename);
++ return retval;
++ }
++ return run_test_loop(loops, test_type, filename);
+}
+
+static int check_file_present(const char *filename)
@@ -498,28 +587,30 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ fprintf(stderr,
+ "usage: %s [options]\n"
+ " -l loops Number of loops to run the test for.\n"
-+ " default is 10'000\n"
-+ " -t testtype Test type to run\n"
-+ " types are: readfile, openreadclose\n"
-+ " default is readfile\n",
-+ progname);
++ " default is %d\n"
++ " -t testtype Test type to run.\n"
++ " types are: readfile, openreadclose, both\n"
++ " default is %s\n"
++ " -f filename Filename to read from, full path, not relative.\n"
++ " default is %s\n",
++ progname,
++ DEFAULT_TEST_LOOPS, DEFAULT_TEST_TYPE, DEFAULT_TEST_FILE);
+}
+
+int main(int argc, char *argv[])
+{
-+ int loops = 10000;
-+ unsigned char buffer[10000];
-+ char c;
-+ char *testtype = "readfile";
+ char *progname;
-+ char *filename;
++ char *testtype = DEFAULT_TEST_TYPE;
++ char *filename = DEFAULT_TEST_FILE;
++ int loops = DEFAULT_TEST_LOOPS;
+ enum test_type test_type;
+ int retval;
++ char c;
+
+ progname = strrchr(argv[0], '/');
+ progname = progname ? 1+progname : argv[0];
+
-+ while (EOF != (c = getopt(argc, argv, "t:hl:"))) {
++ while (EOF != (c = getopt(argc, argv, "t:l:f:h"))) {
+ switch (c) {
+ case 'l':
+ loops = atoi(optarg);
@@ -529,6 +620,10 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ testtype = optarg;
+ break;
+
++ case 'f':
++ filename = optarg;
++ break;
++
+ case 'h':
+ usage(progname);
+ return 0;
@@ -540,22 +635,24 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ }
+
+ if (strcmp(testtype, "readfile") == 0)
-+ test_type = READFILE;
++ test_type = TEST_READFILE;
+ else if (strcmp(testtype, "openreadclose") == 0)
-+ test_type = OPENREADCLOSE;
++ test_type = TEST_OPENREADCLOSE;
++ else if (strcmp(testtype, "both") == 0)
++ test_type = TEST_BOTH;
+ else {
+ usage(progname);
+ return -1;
+ }
+
-+ filename = TEST_FILE;
++ test_readfile_supported();
+
+ retval = check_file_present(filename);
+ if (retval)
+ return retval;
+
-+ retval = do_read_file_test(loops, test_type, TEST_FILE,
-+ &buffer[0], sizeof(buffer));
-+
-+ return retval;
++ return do_read_file_test(loops, test_type, filename);
+}
+--
+2.29.2
+
diff --git a/0004-readfile.2.patch b/0004-readfile.2-new-page-describing-readfile-2.patch
index be3b579d0158f7..27d828412fc8df 100644
--- a/0004-readfile.2.patch
+++ b/0004-readfile.2-new-page-describing-readfile-2.patch
@@ -1,16 +1,24 @@
-From 1dcacd2cfdce9695c9e66e21d6ec0292d66da400 Mon Sep 17 00:00:00 2001
+From 66476698b6ee9695a1f22870c768575bcb3bde27 Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Fri, 12 Jun 2020 12:11:39 +0200
-Subject: [PATCH 4/4] readfile.2
+Subject: [PATCH 4/4] readfile.2: new page describing readfile(2)
+readfile(2) is a new syscall to remove the need to do the
+open/read/close dance for small virtual files in places like procfs or
+sysfs.
+
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
- readfile.2 | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 1 file changed, 229 insertions(+)
- create mode 100644 readfile.2
+ man2/readfile.2 | 159 ++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 159 insertions(+)
+ create mode 100644 man2/readfile.2
+diff --git a/man2/readfile.2 b/man2/readfile.2
+new file mode 100644
+index 000000000000..449e722c3442
--- /dev/null
-+++ b/readfile.2
-@@ -0,0 +1,229 @@
++++ b/man2/readfile.2
+@@ -0,0 +1,159 @@
+.\" This manpage is Copyright (C) 2020 Greg Kroah-Hartman;
+.\" and Copyright (C) 2020 The Linux Foundation
+.\"
@@ -36,7 +44,7 @@ Subject: [PATCH 4/4] readfile.2
+.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
+.\"
-+.TH READFILE 2 2020-06-12 "Linux" "Linux Programmer's Manual"
++.TH READFILE 2 2020-07-04 "Linux" "Linux Programmer's Manual"
+.SH NAME
+readfile \- read a file into a buffer
+.SH SYNOPSIS
@@ -99,7 +107,7 @@ Subject: [PATCH 4/4] readfile.2
+.I pathname
+is interpreted relative to the current working
+directory of the calling process (like
-+.BR open ()).
++.BR openat ()).
+.PP
+If
+.I pathname
@@ -117,33 +125,6 @@ Subject: [PATCH 4/4] readfile.2
+is set appropriately.
+.SH ERRORS
+.TP
-+.B EAGAIN
-+The file descriptor
-+.I fd
-+refers to a file other than a socket and has been marked nonblocking
-+.RB ( O_NONBLOCK ),
-+and the read would block.
-+See
-+.BR open (2)
-+for further details on the
-+.BR O_NONBLOCK
-+flag.
-+.TP
-+.BR EAGAIN " or " EWOULDBLOCK
-+.\" Actually EAGAIN on Linux
-+The file descriptor
-+.I fd
-+refers to a socket and has been marked nonblocking
-+.RB ( O_NONBLOCK ),
-+and the read would block.
-+POSIX.1-2001 allows either error to be returned for this case,
-+and does not require these constants to have the same value,
-+so a portable application should check for both possibilities.
-+.TP
-+.B EBADF
-+.I fd
-+is not a valid file descriptor or is not open for reading.
-+.TP
+.B EFAULT
+.I buf
+is outside your accessible address space.
@@ -153,25 +134,8 @@ Subject: [PATCH 4/4] readfile.2
+.BR signal (7).
+.TP
+.B EINVAL
-+.I fd
-+is attached to an object which is unsuitable for reading;
-+or the file was opened with the
-+.B O_DIRECT
-+flag, and either the address specified in
-+.IR buf ,
-+the value specified in
-+.IR count ,
-+or the file offset is not suitably aligned.
-+.TP
-+.B EINVAL
-+.I fd
-+was created via a call to
-+.BR timerfd_create (2)
-+and the wrong size buffer was given to
-+.BR read ();
-+see
-+.BR timerfd_create (2)
-+for further information.
++.I flags
++was set to a value that is not allowed.
+.TP
+.B EIO
+I/O error.
@@ -192,22 +156,12 @@ Subject: [PATCH 4/4] readfile.2
+section of
+.BR fcntl (2)
+for further details.
-+.TP
-+.B EISDIR
-+.I fd
-+refers to a directory.
-+.PP
-+Other errors may occur, depending on the object connected to
-+.IR fd .
+.SH CONFORMING TO
-+SVr4, 4.3BSD, POSIX.1-2001.
++None, this is a Linux-specific system call at this point in time.
+.SH NOTES
-+The types
++The type
+.I size_t
-+and
-+.I ssize_t
-+are, respectively,
-+unsigned and signed integer data types specified by POSIX.1.
++is an unsigned integer data type specified by POSIX.1.
+.PP
+On Linux,
+.BR read ()
@@ -216,22 +170,6 @@ Subject: [PATCH 4/4] readfile.2
+returning the number of bytes actually transferred.
+.\" commit e28cc71572da38a5a12c1cfe4d7032017adccf69
+(This is true on both 32-bit and 64-bit systems.)
-+.PP
-+On NFS filesystems, reading small amounts of data will update the
-+timestamp only the first time, subsequent calls may not do so.
-+This is caused
-+by client side attribute caching, because most if not all NFS clients
-+leave
-+.I st_atime
-+(last file access time)
-+updates to the server, and client side reads satisfied from the
-+client's cache will not cause
-+.I st_atime
-+updates on the server as there are no
-+server-side reads.
-+UNIX semantics can be obtained by disabling client-side attribute caching,
-+but in most situations this will substantially
-+increase server load and decrease performance.
+.SH BUGS
+None yet!
+.SH SEE ALSO
@@ -240,3 +178,6 @@ Subject: [PATCH 4/4] readfile.2
+.BR openat (2),
+.BR read (2),
+.BR fread (3)
+--
+2.29.2
+
diff --git a/series b/series
index 648d3c3c9218a2..74a91413e46449 100644
--- a/series
+++ b/series
@@ -3,7 +3,7 @@
0001-readfile-implement-readfile-syscall.patch
0002-arch-wire-up-the-readfile-syscall.patch
0003-selftests-add-readfile-2-selftests.patch
-0004-readfile.2.patch
+0004-readfile.2-new-page-describing-readfile-2.patch
spdxcheck-print-out-files-without-any-spdx-lines.patch
0001-tty-n_r3964-locking-fixups.patch