All of lore.kernel.org
 help / color / mirror / Atom feed
* + proc-mandate-proc_lseek-in-struct-proc_ops.patch added to -mm tree
@ 2021-03-28 22:15 akpm
  2021-04-07 19:55 ` [PATCH] proc: smoke test lseek() Alexey Dobriyan
  0 siblings, 1 reply; 4+ messages in thread
From: akpm @ 2021-03-28 22:15 UTC (permalink / raw)
  To: adobriyan, mm-commits


The patch titled
     Subject: proc: mandate ->proc_lseek in "struct proc_ops"
has been added to the -mm tree.  Its filename is
     proc-mandate-proc_lseek-in-struct-proc_ops.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/proc-mandate-proc_lseek-in-struct-proc_ops.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/proc-mandate-proc_lseek-in-struct-proc_ops.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Alexey Dobriyan <adobriyan@gmail.com>
Subject: proc: mandate ->proc_lseek in "struct proc_ops"

Now that proc_ops are separate from file_operations and other operations
it easy to check all instances to have ->proc_lseek hook and remove check
in main code.

Note:
nonseekable_open() files naturally don't require ->proc_lseek.

Garbage collect pde_lseek() function.

Link: https://lkml.kernel.org/r/YFYX0Bzwxlc7aBa/@localhost.localdomain
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/isdn/capi/kcapi_proc.c                     |    1 
 drivers/net/wireless/intersil/hostap/hostap_proc.c |    1 
 drivers/scsi/esas2r/esas2r_main.c                  |    1 
 fs/proc/inode.c                                    |   14 +----------
 include/linux/proc_fs.h                            |    1 
 5 files changed, 6 insertions(+), 12 deletions(-)

--- a/drivers/isdn/capi/kcapi_proc.c~proc-mandate-proc_lseek-in-struct-proc_ops
+++ a/drivers/isdn/capi/kcapi_proc.c
@@ -201,6 +201,7 @@ static ssize_t empty_read(struct file *f
 
 static const struct proc_ops empty_proc_ops = {
 	.proc_read	= empty_read,
+	.proc_lseek	= default_llseek,
 };
 
 // ---------------------------------------------------------------------------
--- a/drivers/net/wireless/intersil/hostap/hostap_proc.c~proc-mandate-proc_lseek-in-struct-proc_ops
+++ a/drivers/net/wireless/intersil/hostap/hostap_proc.c
@@ -227,6 +227,7 @@ static ssize_t prism2_aux_dump_proc_no_r
 
 static const struct proc_ops prism2_aux_dump_proc_ops = {
 	.proc_read	= prism2_aux_dump_proc_no_read,
+	.proc_lseek	= default_llseek,
 };
 
 
--- a/drivers/scsi/esas2r/esas2r_main.c~proc-mandate-proc_lseek-in-struct-proc_ops
+++ a/drivers/scsi/esas2r/esas2r_main.c
@@ -617,6 +617,7 @@ static const struct file_operations esas
 };
 
 static const struct proc_ops esas2r_proc_ops = {
+	.proc_lseek		= default_llseek,
 	.proc_ioctl		= esas2r_proc_ioctl,
 #ifdef CONFIG_COMPAT
 	.proc_compat_ioctl	= compat_ptr_ioctl,
--- a/fs/proc/inode.c~proc-mandate-proc_lseek-in-struct-proc_ops
+++ a/fs/proc/inode.c
@@ -273,25 +273,15 @@ void proc_entry_rundown(struct proc_dir_
 	spin_unlock(&de->pde_unload_lock);
 }
 
-static loff_t pde_lseek(struct proc_dir_entry *pde, struct file *file, loff_t offset, int whence)
-{
-	typeof_member(struct proc_ops, proc_lseek) lseek;
-
-	lseek = pde->proc_ops->proc_lseek;
-	if (!lseek)
-		lseek = default_llseek;
-	return lseek(file, offset, whence);
-}
-
 static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
 {
 	struct proc_dir_entry *pde = PDE(file_inode(file));
 	loff_t rv = -EINVAL;
 
 	if (pde_is_permanent(pde)) {
-		return pde_lseek(pde, file, offset, whence);
+		return pde->proc_ops->proc_lseek(file, offset, whence);
 	} else if (use_pde(pde)) {
-		rv = pde_lseek(pde, file, offset, whence);
+		rv = pde->proc_ops->proc_lseek(file, offset, whence);
 		unuse_pde(pde);
 	}
 	return rv;
--- a/include/linux/proc_fs.h~proc-mandate-proc_lseek-in-struct-proc_ops
+++ a/include/linux/proc_fs.h
@@ -32,6 +32,7 @@ struct proc_ops {
 	ssize_t	(*proc_read)(struct file *, char __user *, size_t, loff_t *);
 	ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
 	ssize_t	(*proc_write)(struct file *, const char __user *, size_t, loff_t *);
+	/* mandatory unless nonseekable_open() or equivalent is used */
 	loff_t	(*proc_lseek)(struct file *, loff_t, int);
 	int	(*proc_release)(struct inode *, struct file *);
 	__poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
_

Patches currently in -mm which might be from adobriyan@gmail.com are

proc-mandate-proc_lseek-in-struct-proc_ops.patch
proc-delete-redundant-subset=pid-check.patch
proc-test-subset=pid.patch


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] proc: smoke test lseek()
  2021-03-28 22:15 + proc-mandate-proc_lseek-in-struct-proc_ops.patch added to -mm tree akpm
@ 2021-04-07 19:55 ` Alexey Dobriyan
  2021-04-07 19:58   ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2021-04-07 19:55 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-fsdevel

Now that ->proc_lseek has been made mandatory it would be nice to test
that nothing has been forgotten.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

		May want to fold into
	proc-mandate-proc_lseek-in-struct-proc_ops.patch

 tools/testing/selftests/proc/read.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/tools/testing/selftests/proc/read.c
+++ b/tools/testing/selftests/proc/read.c
@@ -14,7 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 // Test
-// 1) read of every file in /proc
+// 1) read and lseek on every file in /proc
 // 2) readlink of every symlink in /proc
 // 3) recursively (1) + (2) for every directory in /proc
 // 4) write to /proc/*/clear_refs and /proc/*/task/*/clear_refs
@@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
 	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
 	if (fd == -1)
 		return;
+	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
+	(void)lseek(fd, 0, SEEK_SET);
 	rv = read(fd, buf, sizeof(buf));
 	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
 	close(fd);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] proc: smoke test lseek()
  2021-04-07 19:55 ` [PATCH] proc: smoke test lseek() Alexey Dobriyan
@ 2021-04-07 19:58   ` Matthew Wilcox
  2021-04-07 20:06     ` Alexey Dobriyan
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2021-04-07 19:58 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, linux-fsdevel

On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> Now that ->proc_lseek has been made mandatory it would be nice to test
> that nothing has been forgotten.

> @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
>  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
>  	if (fd == -1)
>  		return;
> +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> +	(void)lseek(fd, 0, SEEK_SET);
>  	rv = read(fd, buf, sizeof(buf));
>  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
>  	close(fd);

why throw away the return value?  if it returns an error seeking to
offset 0, something is terribly wrong.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] proc: smoke test lseek()
  2021-04-07 19:58   ` Matthew Wilcox
@ 2021-04-07 20:06     ` Alexey Dobriyan
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2021-04-07 20:06 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, linux-kernel, linux-fsdevel

On Wed, Apr 07, 2021 at 08:58:09PM +0100, Matthew Wilcox wrote:
> On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> > Now that ->proc_lseek has been made mandatory it would be nice to test
> > that nothing has been forgotten.
> 
> > @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
> >  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
> >  	if (fd == -1)
> >  		return;
> > +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> > +	(void)lseek(fd, 0, SEEK_SET);
> >  	rv = read(fd, buf, sizeof(buf));
> >  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
> >  	close(fd);
> 
> why throw away the return value?  if it returns an error seeking to
> offset 0, something is terribly wrong.

Some files may use nonseekable_open().
This smoke test doesn't verify that seeking is done correctly anyway.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-07 20:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28 22:15 + proc-mandate-proc_lseek-in-struct-proc_ops.patch added to -mm tree akpm
2021-04-07 19:55 ` [PATCH] proc: smoke test lseek() Alexey Dobriyan
2021-04-07 19:58   ` Matthew Wilcox
2021-04-07 20:06     ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.